|
258 | 258 | end
|
259 | 259 | end
|
260 | 260 |
|
261 |
| - context "given two one-dimensional arrays where the actual has added elements" do |
| 261 | + context "given two one-dimensional arrays where the actual has extra elements" do |
262 | 262 | it "returns a message along with the diff" do
|
263 | 263 | actual_output = described_class.call(
|
264 | 264 | expected: ["foo", "bar"],
|
|
307 | 307 | context "given the same hash" do
|
308 | 308 | it "returns an empty string" do
|
309 | 309 | output = described_class.call(
|
310 |
| - expected: { foo: "bar" }, |
311 |
| - actual: { foo: "bar" } |
| 310 | + expected: { name: "Elliot" }, |
| 311 | + actual: { name: "Elliot" } |
312 | 312 | )
|
313 | 313 |
|
314 | 314 | expect(output).to eq("")
|
315 | 315 | end
|
316 | 316 | end
|
317 | 317 |
|
| 318 | + context "given two equal-size, one-dimensional hashes where the same key has differing numbers" do |
| 319 | + it "returns a message along with the diff" do |
| 320 | + actual_output = described_class.call( |
| 321 | + expected: { tall: 12, grande: 19, venti: 20 }, |
| 322 | + actual: { tall: 12, grande: 16, venti: 20 } |
| 323 | + ) |
| 324 | + |
| 325 | + expected_output = <<~STR |
| 326 | + Differing hashes. |
| 327 | +
|
| 328 | + Expected: { tall: 12, grande: 19, venti: 20 } |
| 329 | + Actual: { tall: 12, grande: 16, venti: 20 } |
| 330 | +
|
| 331 | + Details: |
| 332 | +
|
| 333 | + - *[:grande]: Differing numbers. |
| 334 | + Expected: 19 |
| 335 | + Actual: 16 |
| 336 | + STR |
| 337 | + |
| 338 | + expect(actual_output).to eq(expected_output) |
| 339 | + end |
| 340 | + end |
| 341 | + |
| 342 | + context "given two equal-size, one-dimensional hashes where the same key has differing symbols" do |
| 343 | + it "returns a message along with the diff" do |
| 344 | + actual_output = described_class.call( |
| 345 | + expected: { tall: :small, grande: :grand, venti: :large }, |
| 346 | + actual: { tall: :small, grande: :medium, venti: :large }, |
| 347 | + ) |
| 348 | + |
| 349 | + expected_output = <<~STR |
| 350 | + Differing hashes. |
| 351 | +
|
| 352 | + Expected: { tall: :small, grande: :grand, venti: :large } |
| 353 | + Actual: { tall: :small, grande: :medium, venti: :large } |
| 354 | +
|
| 355 | + Details: |
| 356 | +
|
| 357 | + - *[:grande]: Differing symbols. |
| 358 | + Expected: :grand |
| 359 | + Actual: :medium |
| 360 | + STR |
| 361 | + |
| 362 | + expect(actual_output).to eq(expected_output) |
| 363 | + end |
| 364 | + end |
| 365 | + |
| 366 | + context "given two equal-size, one-dimensional hashes where the same key has differing strings" do |
| 367 | + it "returns a message along with the diff" do |
| 368 | + actual_output = described_class.call( |
| 369 | + expected: { tall: "small", grande: "grand", venti: "large" }, |
| 370 | + actual: { tall: "small", grande: "medium", venti: "large" }, |
| 371 | + ) |
| 372 | + |
| 373 | + expected_output = <<~STR |
| 374 | + Differing hashes. |
| 375 | +
|
| 376 | + Expected: { tall: "small", grande: "grand", venti: "large" } |
| 377 | + Actual: { tall: "small", grande: "medium", venti: "large" } |
| 378 | +
|
| 379 | + Details: |
| 380 | +
|
| 381 | + - *[:grande]: Differing strings. |
| 382 | + Expected: "grand" |
| 383 | + Actual: "medium" |
| 384 | + STR |
| 385 | + |
| 386 | + expect(actual_output).to eq(expected_output) |
| 387 | + end |
| 388 | + end |
| 389 | + |
| 390 | + context "given two equal-size, one-dimensional hashes where the same key has differing objects" do |
| 391 | + it "returns a message along with the diff" do |
| 392 | + actual_output = described_class.call( |
| 393 | + expected: { |
| 394 | + steve: SuperDiff::Test::Person.new(name: "Jobs"), |
| 395 | + susan: SuperDiff::Test::Person.new(name: "Kare") |
| 396 | + }, |
| 397 | + actual: { |
| 398 | + steve: SuperDiff::Test::Person.new(name: "Wozniak"), |
| 399 | + susan: SuperDiff::Test::Person.new(name: "Kare") |
| 400 | + } |
| 401 | + ) |
| 402 | + |
| 403 | + expected_output = <<~STR |
| 404 | + Differing hashes. |
| 405 | +
|
| 406 | + Expected: { steve: #<Person name="Jobs">, susan: #<Person name="Kare"> } |
| 407 | + Actual: { steve: #<Person name="Wozniak">, susan: #<Person name="Kare"> } |
| 408 | +
|
| 409 | + Details: |
| 410 | +
|
| 411 | + - *[:steve]: Differing objects. |
| 412 | + Expected: #<Person name="Jobs"> |
| 413 | + Actual: #<Person name="Wozniak"> |
| 414 | + STR |
| 415 | + |
| 416 | + expect(actual_output).to eq(expected_output) |
| 417 | + end |
| 418 | + end |
| 419 | + |
| 420 | + context "given two equal-size, one-dimensional hashes where the actual has extra keys" do |
| 421 | + it "returns a message along with the diff" do |
| 422 | + actual_output = described_class.call( |
| 423 | + expected: { latte: 4.5 }, |
| 424 | + actual: { latte: 4.5, mocha: 3.5, cortado: 3 } |
| 425 | + ) |
| 426 | + |
| 427 | + expected_output = <<~STR |
| 428 | + Differing hashes. |
| 429 | +
|
| 430 | + Expected: { latte: 4.5 } |
| 431 | + Actual: { latte: 4.5, mocha: 3.5, cortado: 3 } |
| 432 | +
|
| 433 | + Details: |
| 434 | +
|
| 435 | + - *[? -> :mocha]: Actual has extra key (with value of 3.5). |
| 436 | + - *[? -> :cortado]: Actual has extra key (with value of 3). |
| 437 | + STR |
| 438 | + |
| 439 | + expect(actual_output).to eq(expected_output) |
| 440 | + end |
| 441 | + end |
| 442 | + |
| 443 | + context "given two equal-size, one-dimensional hashes where the actual has missing keys" do |
| 444 | + it "returns a message along with the diff" do |
| 445 | + actual_output = described_class.call( |
| 446 | + expected: { latte: 4.5, mocha: 3.5, cortado: 3 }, |
| 447 | + actual: { latte: 4.5 } |
| 448 | + ) |
| 449 | + |
| 450 | + expected_output = <<~STR |
| 451 | + Differing hashes. |
| 452 | +
|
| 453 | + Expected: { latte: 4.5, mocha: 3.5, cortado: 3 } |
| 454 | + Actual: { latte: 4.5 } |
| 455 | +
|
| 456 | + Details: |
| 457 | +
|
| 458 | + - *[:mocha -> ?]: Actual is missing key. |
| 459 | + - *[:cortado -> ?]: Actual is missing key. |
| 460 | + STR |
| 461 | + |
| 462 | + expect(actual_output).to eq(expected_output) |
| 463 | + end |
| 464 | + end |
| 465 | + |
318 | 466 | context "given two objects which == each other" do
|
319 | 467 | it "returns an empty string" do
|
320 | 468 | expected = SuperDiff::Test::Person.new(name: "Elliot")
|
|
0 commit comments