Skip to content

Commit 41621ab

Browse files
committed
Add two more tests for arrays to test use of patience diff
1 parent cd6bd93 commit 41621ab

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

spec/unit/differ_spec.rb

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
end
253253
end
254254

255-
context "given two one-dimensional arrays where the actual has extra elements" do
255+
context "given two one-dimensional arrays where the actual has elements added to the end" do
256256
it "returns a message along with the diff" do
257257
actual_output = described_class.call(
258258
expected: ["bread"],
@@ -275,7 +275,7 @@
275275
end
276276
end
277277

278-
context "given two one-dimensional arrays where the actual has missing elements" do
278+
context "given two one-dimensional arrays where the actual has elements missing from the end" do
279279
it "returns a message along with the diff" do
280280
actual_output = described_class.call(
281281
expected: ["bread", "eggs", "milk"],
@@ -298,6 +298,52 @@
298298
end
299299
end
300300

301+
context "given two one-dimensional arrays where the actual has elements added to the beginning" do
302+
it "returns a message along with the diff" do
303+
actual_output = described_class.call(
304+
expected: ["milk"],
305+
actual: ["bread", "eggs", "milk"]
306+
)
307+
308+
expected_output = <<~STR
309+
Differing arrays.
310+
311+
Expected: ["milk"]
312+
Actual: ["bread", "eggs", "milk"]
313+
314+
Details:
315+
316+
- *[? -> 0]: Actual has extra element "bread".
317+
- *[? -> 1]: Actual has extra element "eggs".
318+
STR
319+
320+
expect(actual_output).to eq(expected_output)
321+
end
322+
end
323+
324+
context "given two one-dimensional arrays where the actual has elements removed from the beginning" do
325+
it "returns a message along with the diff" do
326+
actual_output = described_class.call(
327+
expected: ["bread", "eggs", "milk"],
328+
actual: ["milk"]
329+
)
330+
331+
expected_output = <<~STR
332+
Differing arrays.
333+
334+
Expected: ["bread", "eggs", "milk"]
335+
Actual: ["milk"]
336+
337+
Details:
338+
339+
- *[0 -> ?]: Actual is missing element "bread".
340+
- *[1 -> ?]: Actual is missing element "eggs".
341+
STR
342+
343+
expect(actual_output).to eq(expected_output)
344+
end
345+
end
346+
301347
context "given the same hash" do
302348
it "returns an empty string" do
303349
output = described_class.call(

0 commit comments

Comments
 (0)