|
66 | 66 |
|
67 | 67 | context "given completely different single-line strings" do
|
68 | 68 | 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 | + ) |
81 | 73 |
|
82 |
| - str << color.line do |line| |
83 |
| - line << color.light_red_bg("- foo") |
84 |
| - end |
| 74 | + expected_output = <<~STR |
| 75 | + Differing strings. |
85 | 76 |
|
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 |
90 | 80 |
|
91 | 81 | expect(actual_output).to eq(expected_output)
|
92 | 82 | end
|
93 | 83 | end
|
94 | 84 |
|
95 | 85 | context "given closely different single-line strings" do
|
96 | 86 | 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 | + ) |
107 | 91 |
|
108 |
| - STR |
| 92 | + expected_output = <<~STR |
| 93 | + Differing strings. |
109 | 94 |
|
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 |
113 | 98 |
|
114 | 99 | expect(actual_output).to eq(expected_output)
|
115 | 100 | end
|
|
156 | 141 |
|
157 | 142 | context "given the same array" do
|
158 | 143 | 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 | + ) |
160 | 148 |
|
161 | 149 | expect(output).to eq("")
|
162 | 150 | end
|
|
213 | 201 | context "given two equal-length, one-dimensional arrays with differing strings" do
|
214 | 202 | it "returns a message along with the diff" do
|
215 | 203 | 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"] |
218 | 206 | )
|
219 | 207 |
|
220 | 208 | expected_output = <<~STR
|
221 | 209 | Differing arrays.
|
222 | 210 |
|
223 |
| - Expected: ["foo", "bar", "qux"] |
224 |
| - Actual: ["foo", "baz", "qux"] |
| 211 | + Expected: ["sausage", "egg", "cheese"] |
| 212 | + Actual: ["bacon", "egg", "cheese"] |
225 | 213 |
|
226 | 214 | Details:
|
227 | 215 |
|
228 |
| - - *[1]: Differing strings. |
229 |
| - Expected: "bar" |
230 |
| - Actual: "baz" |
| 216 | + - *[0]: Differing strings. |
| 217 | + Expected: "sausage" |
| 218 | + Actual: "bacon" |
231 | 219 | STR
|
232 | 220 |
|
233 | 221 | expect(actual_output).to eq(expected_output)
|
|
237 | 225 | context "given two equal-length, one-dimensional arrays with differing objects" do
|
238 | 226 | it "returns a message along with the diff" do
|
239 | 227 | 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 | + ], |
242 | 236 | )
|
243 | 237 |
|
244 | 238 | expected_output = <<~STR
|
245 | 239 | Differing arrays.
|
246 | 240 |
|
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">] |
249 | 243 |
|
250 | 244 | Details:
|
251 | 245 |
|
252 | 246 | - *[1]: Differing objects.
|
253 |
| - Expected: #<Person name="Elliot"> |
254 |
| - Actual: #<Person name="Joe"> |
| 247 | + Expected: #<Person name="Jennifer"> |
| 248 | + Actual: #<Person name="Doc"> |
255 | 249 | STR
|
256 | 250 |
|
257 | 251 | expect(actual_output).to eq(expected_output)
|
|
261 | 255 | context "given two one-dimensional arrays where the actual has extra elements" do
|
262 | 256 | it "returns a message along with the diff" do
|
263 | 257 | actual_output = described_class.call(
|
264 |
| - expected: ["foo", "bar"], |
265 |
| - actual: ["foo", "baz", "qux", "bar"] |
| 258 | + expected: ["bread"], |
| 259 | + actual: ["bread", "eggs", "milk"] |
266 | 260 | )
|
267 | 261 |
|
268 | 262 | expected_output = <<~STR
|
269 | 263 | Differing arrays.
|
270 | 264 |
|
271 |
| - Expected: ["foo", "bar"] |
272 |
| - Actual: ["foo", "baz", "qux", "bar"] |
| 265 | + Expected: ["bread"] |
| 266 | + Actual: ["bread", "eggs", "milk"] |
273 | 267 |
|
274 | 268 | Details:
|
275 | 269 |
|
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". |
278 | 272 | STR
|
279 | 273 |
|
280 | 274 | expect(actual_output).to eq(expected_output)
|
|
284 | 278 | context "given two one-dimensional arrays where the actual has missing elements" do
|
285 | 279 | it "returns a message along with the diff" do
|
286 | 280 | actual_output = described_class.call(
|
287 |
| - expected: ["foo", "baz", "qux", "bar"], |
288 |
| - actual: ["foo", "bar"] |
| 281 | + expected: ["bread", "eggs", "milk"], |
| 282 | + actual: ["bread"] |
289 | 283 | )
|
290 | 284 |
|
291 | 285 | expected_output = <<~STR
|
292 | 286 | Differing arrays.
|
293 | 287 |
|
294 |
| - Expected: ["foo", "baz", "qux", "bar"] |
295 |
| - Actual: ["foo", "bar"] |
| 288 | + Expected: ["bread", "eggs", "milk"] |
| 289 | + Actual: ["bread"] |
296 | 290 |
|
297 | 291 | Details:
|
298 | 292 |
|
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". |
301 | 295 | STR
|
302 | 296 |
|
303 | 297 | expect(actual_output).to eq(expected_output)
|
|
307 | 301 | context "given the same hash" do
|
308 | 302 | it "returns an empty string" do
|
309 | 303 | output = described_class.call(
|
310 |
| - expected: { name: "Elliot" }, |
311 |
| - actual: { name: "Elliot" } |
| 304 | + expected: { name: "Marty" }, |
| 305 | + actual: { name: "Marty" } |
312 | 306 | )
|
313 | 307 |
|
314 | 308 | expect(output).to eq("")
|
|
465 | 459 |
|
466 | 460 | context "given two objects which == each other" do
|
467 | 461 | 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") |
470 | 464 |
|
471 | 465 | output = described_class.call(expected: expected, actual: actual)
|
472 | 466 |
|
|
476 | 470 |
|
477 | 471 | context "given two objects which do not == each other" do
|
478 | 472 | 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") |
481 | 475 |
|
482 | 476 | actual_output = described_class.call(expected: expected, actual: actual)
|
483 | 477 |
|
484 | 478 | expected_output = <<~STR
|
485 | 479 | Differing objects.
|
486 | 480 |
|
487 |
| - Expected: #<Person name="Elliot"> |
488 |
| - Actual: #<Person name="Joe"> |
| 481 | + Expected: #<Person name="Marty"> |
| 482 | + Actual: #<Person name="Doc"> |
489 | 483 | STR
|
490 | 484 |
|
491 | 485 | expect(actual_output).to eq(expected_output)
|
|
0 commit comments