Skip to content

Commit cd6bd93

Browse files
committed
Use more realistic examples in tests
1 parent 2203c35 commit cd6bd93

File tree

2 files changed

+61
-72
lines changed

2 files changed

+61
-72
lines changed

lib/super_diff/differ.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ def diff_strings
7171
7272
Expected: #{expected.inspect}
7373
Actual: #{actual.inspect}
74-
75-
Diff:
76-
77-
#{deleted("- #{expected}")}
78-
#{inserted("+ #{actual}")}
7974
OUTPUT
8075
end
8176
end

spec/unit/differ_spec.rb

Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -66,50 +66,35 @@
6666

6767
context "given completely different single-line strings" do
6868
it "returns a message along with the diff" do
69-
actual_output = described_class.call(expected: "foo", actual: "bar")
70-
71-
expected_output = colored do |str, color|
72-
str << color.plain(<<~STR)
73-
Differing strings.
74-
75-
Expected: "foo"
76-
Actual: "bar"
77-
78-
Diff:
79-
80-
STR
69+
actual_output = described_class.call(
70+
expected: "Marty",
71+
actual: "Jennifer"
72+
)
8173

82-
str << color.line do |line|
83-
line << color.light_red_bg("- foo")
84-
end
74+
expected_output = <<~STR
75+
Differing strings.
8576
86-
str << color.line do |line|
87-
line << color.light_green_bg("+ bar")
88-
end
89-
end
77+
Expected: "Marty"
78+
Actual: "Jennifer"
79+
STR
9080

9181
expect(actual_output).to eq(expected_output)
9282
end
9383
end
9484

9585
context "given closely different single-line strings" do
9686
it "returns a message along with the diff" do
97-
actual_output = described_class.call(expected: "foo", actual: "foobar")
98-
99-
expected_output = colored do |str, color|
100-
str << color.plain(<<~STR)
101-
Differing strings.
102-
103-
Expected: "foo"
104-
Actual: "foobar"
105-
106-
Diff:
87+
actual_output = described_class.call(
88+
expected: "Marty",
89+
actual: "Marty McFly"
90+
)
10791

108-
STR
92+
expected_output = <<~STR
93+
Differing strings.
10994
110-
str << color.line(color.light_red_bg("- foo"))
111-
str << color.line(color.light_green_bg("+ foobar"))
112-
end
95+
Expected: "Marty"
96+
Actual: "Marty McFly"
97+
STR
11398

11499
expect(actual_output).to eq(expected_output)
115100
end
@@ -156,7 +141,10 @@
156141

157142
context "given the same array" do
158143
it "returns an empty string" do
159-
output = described_class.call(expected: ["foo"], actual: ["foo"])
144+
output = described_class.call(
145+
expected: ["sausage", "egg", "cheese"],
146+
actual: ["sausage", "egg", "cheese"]
147+
)
160148

161149
expect(output).to eq("")
162150
end
@@ -213,21 +201,21 @@
213201
context "given two equal-length, one-dimensional arrays with differing strings" do
214202
it "returns a message along with the diff" do
215203
actual_output = described_class.call(
216-
expected: ["foo", "bar", "qux"],
217-
actual: ["foo", "baz", "qux"]
204+
expected: ["sausage", "egg", "cheese"],
205+
actual: ["bacon", "egg", "cheese"]
218206
)
219207

220208
expected_output = <<~STR
221209
Differing arrays.
222210
223-
Expected: ["foo", "bar", "qux"]
224-
Actual: ["foo", "baz", "qux"]
211+
Expected: ["sausage", "egg", "cheese"]
212+
Actual: ["bacon", "egg", "cheese"]
225213
226214
Details:
227215
228-
- *[1]: Differing strings.
229-
Expected: "bar"
230-
Actual: "baz"
216+
- *[0]: Differing strings.
217+
Expected: "sausage"
218+
Actual: "bacon"
231219
STR
232220

233221
expect(actual_output).to eq(expected_output)
@@ -237,21 +225,27 @@
237225
context "given two equal-length, one-dimensional arrays with differing objects" do
238226
it "returns a message along with the diff" do
239227
actual_output = described_class.call(
240-
expected: [:foo, SuperDiff::Test::Person.new(name: "Elliot"), :bar],
241-
actual: [:foo, SuperDiff::Test::Person.new(name: "Joe"), :bar],
228+
expected: [
229+
SuperDiff::Test::Person.new(name: "Marty"),
230+
SuperDiff::Test::Person.new(name: "Jennifer")
231+
],
232+
actual: [
233+
SuperDiff::Test::Person.new(name: "Marty"),
234+
SuperDiff::Test::Person.new(name: "Doc")
235+
],
242236
)
243237

244238
expected_output = <<~STR
245239
Differing arrays.
246240
247-
Expected: [:foo, #<Person name="Elliot">, :bar]
248-
Actual: [:foo, #<Person name="Joe">, :bar]
241+
Expected: [#<Person name="Marty">, #<Person name="Jennifer">]
242+
Actual: [#<Person name="Marty">, #<Person name="Doc">]
249243
250244
Details:
251245
252246
- *[1]: Differing objects.
253-
Expected: #<Person name="Elliot">
254-
Actual: #<Person name="Joe">
247+
Expected: #<Person name="Jennifer">
248+
Actual: #<Person name="Doc">
255249
STR
256250

257251
expect(actual_output).to eq(expected_output)
@@ -261,20 +255,20 @@
261255
context "given two one-dimensional arrays where the actual has extra elements" do
262256
it "returns a message along with the diff" do
263257
actual_output = described_class.call(
264-
expected: ["foo", "bar"],
265-
actual: ["foo", "baz", "qux", "bar"]
258+
expected: ["bread"],
259+
actual: ["bread", "eggs", "milk"]
266260
)
267261

268262
expected_output = <<~STR
269263
Differing arrays.
270264
271-
Expected: ["foo", "bar"]
272-
Actual: ["foo", "baz", "qux", "bar"]
265+
Expected: ["bread"]
266+
Actual: ["bread", "eggs", "milk"]
273267
274268
Details:
275269
276-
- *[? -> 1]: Actual has extra element "baz".
277-
- *[? -> 2]: Actual has extra element "qux".
270+
- *[? -> 1]: Actual has extra element "eggs".
271+
- *[? -> 2]: Actual has extra element "milk".
278272
STR
279273

280274
expect(actual_output).to eq(expected_output)
@@ -284,20 +278,20 @@
284278
context "given two one-dimensional arrays where the actual has missing elements" do
285279
it "returns a message along with the diff" do
286280
actual_output = described_class.call(
287-
expected: ["foo", "baz", "qux", "bar"],
288-
actual: ["foo", "bar"]
281+
expected: ["bread", "eggs", "milk"],
282+
actual: ["bread"]
289283
)
290284

291285
expected_output = <<~STR
292286
Differing arrays.
293287
294-
Expected: ["foo", "baz", "qux", "bar"]
295-
Actual: ["foo", "bar"]
288+
Expected: ["bread", "eggs", "milk"]
289+
Actual: ["bread"]
296290
297291
Details:
298292
299-
- *[1 -> ?]: Actual is missing element "baz".
300-
- *[2 -> ?]: Actual is missing element "qux".
293+
- *[1 -> ?]: Actual is missing element "eggs".
294+
- *[2 -> ?]: Actual is missing element "milk".
301295
STR
302296

303297
expect(actual_output).to eq(expected_output)
@@ -307,8 +301,8 @@
307301
context "given the same hash" do
308302
it "returns an empty string" do
309303
output = described_class.call(
310-
expected: { name: "Elliot" },
311-
actual: { name: "Elliot" }
304+
expected: { name: "Marty" },
305+
actual: { name: "Marty" }
312306
)
313307

314308
expect(output).to eq("")
@@ -465,8 +459,8 @@
465459

466460
context "given two objects which == each other" do
467461
it "returns an empty string" do
468-
expected = SuperDiff::Test::Person.new(name: "Elliot")
469-
actual = SuperDiff::Test::Person.new(name: "Elliot")
462+
expected = SuperDiff::Test::Person.new(name: "Marty")
463+
actual = SuperDiff::Test::Person.new(name: "Marty")
470464

471465
output = described_class.call(expected: expected, actual: actual)
472466

@@ -476,16 +470,16 @@
476470

477471
context "given two objects which do not == each other" do
478472
it "returns a message along with a comparison" do
479-
expected = SuperDiff::Test::Person.new(name: "Elliot")
480-
actual = SuperDiff::Test::Person.new(name: "Joe")
473+
expected = SuperDiff::Test::Person.new(name: "Marty")
474+
actual = SuperDiff::Test::Person.new(name: "Doc")
481475

482476
actual_output = described_class.call(expected: expected, actual: actual)
483477

484478
expected_output = <<~STR
485479
Differing objects.
486480
487-
Expected: #<Person name="Elliot">
488-
Actual: #<Person name="Joe">
481+
Expected: #<Person name="Marty">
482+
Actual: #<Person name="Doc">
489483
STR
490484

491485
expect(actual_output).to eq(expected_output)

0 commit comments

Comments
 (0)