|
486 | 486 | end
|
487 | 487 | end
|
488 | 488 |
|
489 |
| - context "given two arrays containing an array with differing values" do |
| 489 | + context "given two arrays containing arrays with differing values" do |
490 | 490 | it "returns a message along with the diff" do
|
491 | 491 | actual_output = described_class.call(
|
492 | 492 | expected: [1, 2, [:a, :b, :c], 4],
|
|
526 | 526 | end
|
527 | 527 | end
|
528 | 528 |
|
529 |
| - context "given two arrays containing a hash with differing values" do |
| 529 | + context "given two arrays containing hashes with differing values" do |
530 | 530 | it "returns a message along with the diff" do
|
531 | 531 | actual_output = described_class.call(
|
532 | 532 | expected: [1, 2, { foo: "bar", baz: "qux" }, 4],
|
|
565 | 565 | end
|
566 | 566 | end
|
567 | 567 |
|
568 |
| - context "given two arrays containing a hash with differing objects" do |
| 568 | + context "given two arrays containing custom objects with differing attributes" do |
569 | 569 | it "returns a message along with the diff" do
|
570 | 570 | actual_output = described_class.call(
|
571 | 571 | expected: [1, 2, SuperDiff::Test::Person.new(name: "Marty"), 4],
|
|
878 | 878 | end
|
879 | 879 | end
|
880 | 880 |
|
| 881 | + context "given two hashes containing arrays with differing values" do |
| 882 | + it "returns a message along with the diff" do |
| 883 | + actual_output = described_class.call( |
| 884 | + expected: { |
| 885 | + name: "Elliot", |
| 886 | + interests: ["music", "football", "programming"], |
| 887 | + age: 30 |
| 888 | + }, |
| 889 | + actual: { |
| 890 | + name: "Elliot", |
| 891 | + interests: ["music", "travel", "programming"], |
| 892 | + age: 30 |
| 893 | + } |
| 894 | + ) |
| 895 | + |
| 896 | + expected_output = <<~STR.strip |
| 897 | + Differing hashes. |
| 898 | +
|
| 899 | + #{ |
| 900 | + colored do |
| 901 | + red_line %(Expected: { name: "Elliot", interests: ["music", "football", "programming"], age: 30 }) |
| 902 | + green_line %( Actual: { name: "Elliot", interests: ["music", "travel", "programming"], age: 30 }) |
| 903 | + end |
| 904 | + } |
| 905 | +
|
| 906 | + Diff: |
| 907 | +
|
| 908 | + #{ |
| 909 | + colored do |
| 910 | + plain_line %( {) |
| 911 | + plain_line %( name: "Elliot",) |
| 912 | + plain_line %( interests: [) |
| 913 | + plain_line %( "music",) |
| 914 | + red_line %(- "football",) |
| 915 | + green_line %(+ "travel",) |
| 916 | + plain_line %( "programming") |
| 917 | + plain_line %( ],) |
| 918 | + plain_line %( age: 30) |
| 919 | + plain_line %( }) |
| 920 | + end |
| 921 | + } |
| 922 | + STR |
| 923 | + |
| 924 | + expect(actual_output).to eq(expected_output) |
| 925 | + end |
| 926 | + end |
| 927 | + |
| 928 | + context "given two hashes containing hashes with differing values" do |
| 929 | + it "returns a message along with the diff" do |
| 930 | + actual_output = described_class.call( |
| 931 | + expected: { |
| 932 | + check_spelling: true, |
| 933 | + substitutions: { |
| 934 | + "YOLO" => "You only live once", |
| 935 | + "BRB" => "Buns, ribs, and bacon", |
| 936 | + "YMMV" => "Your mileage may vary" |
| 937 | + }, |
| 938 | + check_grammar: false |
| 939 | + }, |
| 940 | + actual: { |
| 941 | + check_spelling: true, |
| 942 | + substitutions: { |
| 943 | + "YOLO" => "You only live once", |
| 944 | + "BRB" => "Be right back", |
| 945 | + "YMMV" => "Your mileage may vary" |
| 946 | + }, |
| 947 | + check_grammar: false |
| 948 | + } |
| 949 | + ) |
| 950 | + |
| 951 | + expected_output = <<~STR.strip |
| 952 | + Differing hashes. |
| 953 | +
|
| 954 | + #{ |
| 955 | + colored do |
| 956 | + red_line %(Expected: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Buns, ribs, and bacon", "YMMV" => "Your mileage may vary" }, check_grammar: false }) |
| 957 | + green_line %( Actual: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Be right back", "YMMV" => "Your mileage may vary" }, check_grammar: false }) |
| 958 | + end |
| 959 | + } |
| 960 | +
|
| 961 | + Diff: |
| 962 | +
|
| 963 | + #{ |
| 964 | + colored do |
| 965 | + plain_line %( {) |
| 966 | + plain_line %( check_spelling: true,) |
| 967 | + plain_line %( substitutions: {) |
| 968 | + plain_line %( "YOLO" => "You only live once",) |
| 969 | + red_line %(- "BRB" => "Buns, ribs, and bacon",) |
| 970 | + green_line %(+ "BRB" => "Be right back",) |
| 971 | + plain_line %( "YMMV" => "Your mileage may vary") |
| 972 | + plain_line %( },) |
| 973 | + plain_line %( check_grammar: false) |
| 974 | + plain_line %( }) |
| 975 | + end |
| 976 | + } |
| 977 | + STR |
| 978 | + |
| 979 | + expect(actual_output).to eq(expected_output) |
| 980 | + end |
| 981 | + end |
| 982 | + |
| 983 | + context "given two hashes containing custom objects with differing attributes" do |
| 984 | + it "returns a message along with the diff" do |
| 985 | + actual_output = described_class.call( |
| 986 | + expected: { |
| 987 | + order_id: 1234, |
| 988 | + person: SuperDiff::Test::Person.new(name: "Marty"), |
| 989 | + amount: 350_00 |
| 990 | + }, |
| 991 | + actual: { |
| 992 | + order_id: 1234, |
| 993 | + person: SuperDiff::Test::Person.new(name: "Doc"), |
| 994 | + amount: 350_00 |
| 995 | + }, |
| 996 | + extra_operational_sequencer_classes: [ |
| 997 | + SuperDiff::Test::PersonOperationalSequencer |
| 998 | + ], |
| 999 | + extra_diff_formatter_classes: [ |
| 1000 | + SuperDiff::Test::PersonDiffFormatter |
| 1001 | + ] |
| 1002 | + ) |
| 1003 | + |
| 1004 | + expected_output = <<~STR.strip |
| 1005 | + Differing hashes. |
| 1006 | +
|
| 1007 | + #{ |
| 1008 | + colored do |
| 1009 | + red_line %(Expected: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Marty">, amount: 35000 }) |
| 1010 | + green_line %( Actual: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Doc">, amount: 35000 }) |
| 1011 | + end |
| 1012 | + } |
| 1013 | +
|
| 1014 | + Diff: |
| 1015 | +
|
| 1016 | + #{ |
| 1017 | + colored do |
| 1018 | + plain_line %( {) |
| 1019 | + plain_line %( order_id: 1234,) |
| 1020 | + plain_line %( person: #<SuperDiff::Test::Person {) |
| 1021 | + red_line %(- name: "Marty") |
| 1022 | + green_line %(+ name: "Doc") |
| 1023 | + plain_line %( }>,) |
| 1024 | + plain_line %( amount: 35000) |
| 1025 | + plain_line %( }) |
| 1026 | + end |
| 1027 | + } |
| 1028 | + STR |
| 1029 | + |
| 1030 | + expect(actual_output).to eq(expected_output) |
| 1031 | + end |
| 1032 | + end |
| 1033 | + |
881 | 1034 | context "given two objects which == each other" do
|
882 | 1035 | it "returns an empty string" do
|
883 | 1036 | expected = SuperDiff::Test::Person.new(name: "Marty")
|
|
0 commit comments