|
1104 | 1104 | end
|
1105 | 1105 | end
|
1106 | 1106 |
|
| 1107 | + context "given two hashes which contain all different kinds of values, some which differ" do |
| 1108 | + it "returns a message along with the diff" do |
| 1109 | + actual_output = described_class.call( |
| 1110 | + expected: { |
| 1111 | + customer: { |
| 1112 | + name: "Marty McFly", |
| 1113 | + shipping_address: { |
| 1114 | + line_1: "123 Main St.", |
| 1115 | + city: "Hill Valley", |
| 1116 | + state: "CA", |
| 1117 | + zip: "90382" |
| 1118 | + } |
| 1119 | + }, |
| 1120 | + items: [ |
| 1121 | + { |
| 1122 | + name: "Fender Stratocaster", |
| 1123 | + cost: 100_000, |
| 1124 | + options: ["red", "blue", "green"] |
| 1125 | + }, |
| 1126 | + { name: "Chevy 4x4" } |
| 1127 | + ] |
| 1128 | + }, |
| 1129 | + actual: { |
| 1130 | + customer: { |
| 1131 | + name: "Marty McFly, Jr.", |
| 1132 | + shipping_address: { |
| 1133 | + line_1: "456 Ponderosa Ct.", |
| 1134 | + city: "Hill Valley", |
| 1135 | + state: "CA", |
| 1136 | + zip: "90382" |
| 1137 | + } |
| 1138 | + }, |
| 1139 | + items: [ |
| 1140 | + { |
| 1141 | + name: "Fender Stratocaster", |
| 1142 | + cost: 100_000, |
| 1143 | + options: ["red", "blue", "green"] |
| 1144 | + }, |
| 1145 | + { name: "Mattel Hoverboard" } |
| 1146 | + ] |
| 1147 | + } |
| 1148 | + ) |
| 1149 | + |
| 1150 | + expected_output = <<~STR.strip |
| 1151 | + Differing hashes. |
| 1152 | +
|
| 1153 | + #{ |
| 1154 | + colored do |
| 1155 | + red_line %(Expected: { customer: { name: "Marty McFly", shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }) |
| 1156 | + green_line %( Actual: { customer: { name: "Marty McFly, Jr.", shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] }) |
| 1157 | + end |
| 1158 | + } |
| 1159 | +
|
| 1160 | + Diff: |
| 1161 | +
|
| 1162 | + #{ |
| 1163 | + colored do |
| 1164 | + plain_line %( {) |
| 1165 | + plain_line %( customer: {) |
| 1166 | + red_line %(- name: "Marty McFly",) |
| 1167 | + green_line %(+ name: "Marty McFly, Jr.",) |
| 1168 | + plain_line %( shipping_address: {) |
| 1169 | + red_line %(- line_1: "123 Main St.",) |
| 1170 | + green_line %(+ line_1: "456 Ponderosa Ct.",) |
| 1171 | + plain_line %( city: "Hill Valley",) |
| 1172 | + plain_line %( state: "CA",) |
| 1173 | + plain_line %( zip: "90382") |
| 1174 | + plain_line %( }) |
| 1175 | + plain_line %( },) |
| 1176 | + plain_line %( items: [) |
| 1177 | + plain_line %( {) |
| 1178 | + plain_line %( name: "Fender Stratocaster",) |
| 1179 | + plain_line %( cost: 100000,) |
| 1180 | + plain_line %( options: ["red", "blue", "green"]) |
| 1181 | + plain_line %( },) |
| 1182 | + plain_line %( {) |
| 1183 | + red_line %(- name: "Chevy 4x4") |
| 1184 | + green_line %(+ name: "Mattel Hoverboard") |
| 1185 | + plain_line %( }) |
| 1186 | + plain_line %( ]) |
| 1187 | + plain_line %( }) |
| 1188 | + end |
| 1189 | + } |
| 1190 | + STR |
| 1191 | + |
| 1192 | + expect(actual_output).to eq(expected_output) |
| 1193 | + end |
| 1194 | + end |
| 1195 | + |
1107 | 1196 | context "given two objects which == each other" do
|
1108 | 1197 | it "returns an empty string" do
|
1109 | 1198 | expected = SuperDiff::Test::Person.new(name: "Marty")
|
|
0 commit comments