Skip to content

Commit

Permalink
Array + Hash shared/nested specs for #fetch_path
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Aug 11, 2017
1 parent 98bcbc4 commit 2461778
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions spec/core_ext/shared/nested_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@
]
}

context "#fetch_path" do
it "on a empty existing nested hash" do
expect(array.fetch_path(0, "a")).to be_nil
expect(array.fetch_path(0, 1)).to be_nil
end

it "on a existing nested hash" do
expect(array.fetch_path(1, :a)).to be_nil
expect(array.fetch_path(1, :b)).to eq("b")
expect(array.fetch_path(1, :c)).to be_nil
end

it "on a deeply nested hash" do
expect(array.fetch_path(2, 1)).to eq(1)
expect(array.fetch_path(2, 2)).to eq(2 => 2)
expect(array.fetch_path(2, 2, 2)).to eq(2)
expect(array.fetch_path(2, 3)).to be_nil
expect(array.fetch_path(2, 2, 3)).to be_nil
end

it "on a deeply nested hash/array" do
expect(array.fetch_path(3, "a", 0, "a1")).to eq(1)
expect(array.fetch_path(3, "a", 1, "a2")).to eq(2)
expect(array.fetch_path(3, "a", 2, "a3")).to be_nil
end
end

context "#store_path" do
it "on a empty existing nested hash" do
array.store_path(0, "a", 1)
Expand Down Expand Up @@ -61,6 +88,31 @@
}
}

context "#fetch_path" do
it "on a empty existing nested array" do
expect(hash.fetch_path("a", 0)).to be_nil
expect(hash.fetch_path("a", 0, 0)).to be_nil
end

it "on a existing nested array" do
expect(hash.fetch_path("b", 0)).to eq(1)
expect(hash.fetch_path("b", 2)).to eq(3)
expect(hash.fetch_path("b", 3)).to be_nil
expect(hash.fetch_path("b", 0, 0)).to be_nil
end

it "on a deeply nested array" do
expect(hash.fetch_path("c", 1, 0)).to eq(2)
expect(hash.fetch_path("c", 1, 1)).to eq(3)
end

it "on a deeply nested hash/array" do
expect(hash.fetch_path("d", 1, "2")).to eq(2)
expect(hash.fetch_path("d", 1, "3", 2)).to eq(3)
expect(hash.fetch_path("d", 1, "3", 4)).to be_nil
end
end

context "#store_path" do
it "on a empty existing nested array" do
hash.store_path("a", 0, 1)
Expand Down

0 comments on commit 2461778

Please # to comment.