super_diff 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +65 -26
  3. data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
  4. data/lib/super_diff/active_record/differs.rb +1 -1
  5. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  7. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
  8. data/lib/super_diff/active_record/object_inspection.rb +1 -1
  9. data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
  10. data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
  11. data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
  12. data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
  13. data/lib/super_diff/active_record/operation_trees.rb +1 -1
  14. data/lib/super_diff/active_record.rb +7 -15
  15. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
  16. data/lib/super_diff/active_support/differs.rb +1 -1
  17. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -1,57 +1,60 @@
1
1
  shared_examples_for "integration with HashWithIndifferentAccess" do
2
2
  describe "and RSpec's #eq matcher" do
3
- context "when the actual value is a HashWithIndifferentAccess" do
3
+ context "when the actual value is a HashWithIndifferentAccess" do
4
4
  context "and both hashes are one-dimensional" do
5
5
  context "and the expected hash contains symbol keys" do
6
6
  it "produces the correct output" do
7
7
  as_both_colored_and_uncolored do |color_enabled|
8
8
  snippet = <<~TEST.strip
9
+ actual = HashWithIndifferentAccess.new({
10
+ line_1: "456 Ponderosa Ct.",
11
+ city: "Oakland",
12
+ state: "CA",
13
+ zip: "91234",
14
+ })
9
15
  expected = {
10
16
  line_1: "123 Main St.",
11
17
  city: "Hill Valley",
12
18
  state: "CA",
13
19
  zip: "90382",
14
20
  }
15
- actual = HashWithIndifferentAccess.new({
16
- line_1: "456 Ponderosa Ct.",
17
- city: "Oakland",
18
- state: "CA",
19
- zip: "91234",
20
- })
21
21
  expect(actual).to eq(expected)
22
22
  TEST
23
23
  program = make_program(snippet, color_enabled: color_enabled)
24
24
 
25
- expected_output = build_expected_output(
26
- color_enabled: color_enabled,
27
- snippet: "expect(actual).to eq(expected)",
28
- expectation: proc {
29
- line do
30
- plain %|Expected |
31
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
32
- end
33
-
34
- line do
35
- plain %| to eq |
36
- expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
37
- end
38
- },
39
- diff: proc {
40
- plain_line %| #<HashWithIndifferentAccess {|
41
- expected_line %|- "line_1" => "123 Main St.",|
42
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
43
- expected_line %|- "city" => "Hill Valley",|
44
- actual_line %|+ "city" => "Oakland",|
45
- plain_line %| "state" => "CA",|
46
- expected_line %|- "zip" => "90382"|
47
- actual_line %|+ "zip" => "91234"|
48
- plain_line %| }>|
49
- },
50
- )
51
-
52
- expect(program).
53
- to produce_output_when_run(expected_output).
54
- in_color(color_enabled)
25
+ expected_output =
26
+ build_expected_output(
27
+ color_enabled: color_enabled,
28
+ snippet: "expect(actual).to eq(expected)",
29
+ expectation:
30
+ proc do
31
+ line do
32
+ plain "Expected "
33
+ actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
34
+ end
35
+
36
+ line do
37
+ plain " to eq "
38
+ expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
39
+ end
40
+ end,
41
+ diff:
42
+ proc do
43
+ plain_line " #<HashWithIndifferentAccess {"
44
+ expected_line %|- "line_1" => "123 Main St.",|
45
+ actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
46
+ expected_line %|- "city" => "Hill Valley",|
47
+ actual_line %|+ "city" => "Oakland",|
48
+ plain_line %| "state" => "CA",|
49
+ expected_line %|- "zip" => "90382"|
50
+ actual_line %|+ "zip" => "91234"|
51
+ plain_line " }>"
52
+ end
53
+ )
54
+
55
+ expect(program).to produce_output_when_run(
56
+ expected_output
57
+ ).in_color(color_enabled)
55
58
  end
56
59
  end
57
60
  end
@@ -60,52 +63,55 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
60
63
  it "produces the correct output" do
61
64
  as_both_colored_and_uncolored do |color_enabled|
62
65
  snippet = <<~TEST.strip
66
+ actual = HashWithIndifferentAccess.new({
67
+ line_1: "456 Ponderosa Ct.",
68
+ city: "Oakland",
69
+ state: "CA",
70
+ zip: "91234",
71
+ })
63
72
  expected = {
64
73
  "line_1" => "123 Main St.",
65
74
  "city" => "Hill Valley",
66
75
  "state" => "CA",
67
76
  "zip" => "90382",
68
77
  }
69
- actual = HashWithIndifferentAccess.new({
70
- line_1: "456 Ponderosa Ct.",
71
- city: "Oakland",
72
- state: "CA",
73
- zip: "91234",
74
- })
75
78
  expect(actual).to eq(expected)
76
79
  TEST
77
80
  program = make_program(snippet, color_enabled: color_enabled)
78
81
 
79
- expected_output = build_expected_output(
80
- color_enabled: color_enabled,
81
- snippet: "expect(actual).to eq(expected)",
82
- expectation: proc {
83
- line do
84
- plain %|Expected |
85
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
86
- end
87
-
88
- line do
89
- plain %| to eq |
90
- expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
91
- end
92
- },
93
- diff: proc {
94
- plain_line %| #<HashWithIndifferentAccess {|
95
- expected_line %|- "line_1" => "123 Main St.",|
96
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
97
- expected_line %|- "city" => "Hill Valley",|
98
- actual_line %|+ "city" => "Oakland",|
99
- plain_line %| "state" => "CA",|
100
- expected_line %|- "zip" => "90382"|
101
- actual_line %|+ "zip" => "91234"|
102
- plain_line %| }>|
103
- },
104
- )
105
-
106
- expect(program).
107
- to produce_output_when_run(expected_output).
108
- in_color(color_enabled)
82
+ expected_output =
83
+ build_expected_output(
84
+ color_enabled: color_enabled,
85
+ snippet: "expect(actual).to eq(expected)",
86
+ expectation:
87
+ proc do
88
+ line do
89
+ plain "Expected "
90
+ actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
91
+ end
92
+
93
+ line do
94
+ plain " to eq "
95
+ expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
96
+ end
97
+ end,
98
+ diff:
99
+ proc do
100
+ plain_line " #<HashWithIndifferentAccess {"
101
+ expected_line %|- "line_1" => "123 Main St.",|
102
+ actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
103
+ expected_line %|- "city" => "Hill Valley",|
104
+ actual_line %|+ "city" => "Oakland",|
105
+ plain_line %| "state" => "CA",|
106
+ expected_line %|- "zip" => "90382"|
107
+ actual_line %|+ "zip" => "91234"|
108
+ plain_line " }>"
109
+ end
110
+ )
111
+
112
+ expect(program).to produce_output_when_run(
113
+ expected_output
114
+ ).in_color(color_enabled)
109
115
  end
110
116
  end
111
117
  end
@@ -118,106 +124,112 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
118
124
  it "produces the correct output" do
119
125
  as_both_colored_and_uncolored do |color_enabled|
120
126
  snippet = <<~TEST.strip
127
+ actual = {
128
+ line_1: "123 Main St.",
129
+ city: "Hill Valley",
130
+ state: "CA",
131
+ zip: "90382",
132
+ }
121
133
  expected = HashWithIndifferentAccess.new({
122
134
  line_1: "456 Ponderosa Ct.",
123
135
  city: "Oakland",
124
136
  state: "CA",
125
137
  zip: "91234",
126
138
  })
127
- actual = {
128
- line_1: "123 Main St.",
129
- city: "Hill Valley",
130
- state: "CA",
131
- zip: "90382",
132
- }
133
139
  expect(actual).to eq(expected)
134
140
  TEST
135
141
  program = make_program(snippet, color_enabled: color_enabled)
136
142
 
137
- expected_output = build_expected_output(
138
- color_enabled: color_enabled,
139
- snippet: "expect(actual).to eq(expected)",
140
- expectation: proc {
141
- line do
142
- plain %|Expected |
143
- actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
144
- end
145
-
146
- line do
147
- plain %| to eq |
148
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
149
- end
150
- },
151
- diff: proc {
152
- plain_line %| #<HashWithIndifferentAccess {|
153
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
154
- actual_line %|+ "line_1" => "123 Main St.",|
155
- expected_line %|- "city" => "Oakland",|
156
- actual_line %|+ "city" => "Hill Valley",|
157
- plain_line %| "state" => "CA",|
158
- expected_line %|- "zip" => "91234"|
159
- actual_line %|+ "zip" => "90382"|
160
- plain_line %| }>|
161
- },
162
- )
163
-
164
- expect(program).
165
- to produce_output_when_run(expected_output).
166
- in_color(color_enabled)
143
+ expected_output =
144
+ build_expected_output(
145
+ color_enabled: color_enabled,
146
+ snippet: "expect(actual).to eq(expected)",
147
+ expectation:
148
+ proc do
149
+ line do
150
+ plain "Expected "
151
+ actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
152
+ end
153
+
154
+ line do
155
+ plain " to eq "
156
+ expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
157
+ end
158
+ end,
159
+ diff:
160
+ proc do
161
+ plain_line " #<HashWithIndifferentAccess {"
162
+ expected_line %|- "line_1" => "456 Ponderosa Ct.",|
163
+ actual_line %|+ "line_1" => "123 Main St.",|
164
+ expected_line %|- "city" => "Oakland",|
165
+ actual_line %|+ "city" => "Hill Valley",|
166
+ plain_line %| "state" => "CA",|
167
+ expected_line %|- "zip" => "91234"|
168
+ actual_line %|+ "zip" => "90382"|
169
+ plain_line " }>"
170
+ end
171
+ )
172
+
173
+ expect(program).to produce_output_when_run(
174
+ expected_output
175
+ ).in_color(color_enabled)
167
176
  end
168
177
  end
169
178
  end
170
179
 
171
- context "and the actual hash contains string keys" do
180
+ context "and the actual hash contains string keys" do
172
181
  it "produces the correct output" do
173
182
  as_both_colored_and_uncolored do |color_enabled|
174
183
  snippet = <<~TEST.strip
184
+ actual = {
185
+ "line_1" => "123 Main St.",
186
+ "city" => "Hill Valley",
187
+ "state" => "CA",
188
+ "zip" => "90382",
189
+ }
175
190
  expected = HashWithIndifferentAccess.new({
176
191
  line_1: "456 Ponderosa Ct.",
177
192
  city: "Oakland",
178
193
  state: "CA",
179
194
  zip: "91234",
180
195
  })
181
- actual = {
182
- "line_1" => "123 Main St.",
183
- "city" => "Hill Valley",
184
- "state" => "CA",
185
- "zip" => "90382",
186
- }
187
196
  expect(actual).to eq(expected)
188
197
  TEST
189
198
  program = make_program(snippet, color_enabled: color_enabled)
190
199
 
191
- expected_output = build_expected_output(
192
- color_enabled: color_enabled,
193
- snippet: "expect(actual).to eq(expected)",
194
- expectation: proc {
195
- line do
196
- plain %|Expected |
197
- actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
198
- end
199
-
200
- line do
201
- plain %| to eq |
202
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
203
- end
204
- },
205
- diff: proc {
206
- plain_line %| #<HashWithIndifferentAccess {|
207
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
208
- actual_line %|+ "line_1" => "123 Main St.",|
209
- expected_line %|- "city" => "Oakland",|
210
- actual_line %|+ "city" => "Hill Valley",|
211
- plain_line %| "state" => "CA",|
212
- expected_line %|- "zip" => "91234"|
213
- actual_line %|+ "zip" => "90382"|
214
- plain_line %| }>|
215
- },
216
- )
217
-
218
- expect(program).
219
- to produce_output_when_run(expected_output).
220
- in_color(color_enabled)
200
+ expected_output =
201
+ build_expected_output(
202
+ color_enabled: color_enabled,
203
+ snippet: "expect(actual).to eq(expected)",
204
+ expectation:
205
+ proc do
206
+ line do
207
+ plain "Expected "
208
+ actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
209
+ end
210
+
211
+ line do
212
+ plain " to eq "
213
+ expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
214
+ end
215
+ end,
216
+ diff:
217
+ proc do
218
+ plain_line " #<HashWithIndifferentAccess {"
219
+ expected_line %|- "line_1" => "456 Ponderosa Ct.",|
220
+ actual_line %|+ "line_1" => "123 Main St.",|
221
+ expected_line %|- "city" => "Oakland",|
222
+ actual_line %|+ "city" => "Hill Valley",|
223
+ plain_line %| "state" => "CA",|
224
+ expected_line %|- "zip" => "91234"|
225
+ actual_line %|+ "zip" => "90382"|
226
+ plain_line " }>"
227
+ end
228
+ )
229
+
230
+ expect(program).to produce_output_when_run(
231
+ expected_output
232
+ ).in_color(color_enabled)
221
233
  end
222
234
  end
223
235
  end
@@ -228,6 +240,16 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
228
240
  it "produces the correct output" do
229
241
  as_both_colored_and_uncolored do |color_enabled|
230
242
  snippet = <<~TEST.strip
243
+ actual = {
244
+ shipments: [
245
+ {
246
+ estimated_delivery: {
247
+ from: '2019-05-06',
248
+ to: '2019-05-09'
249
+ }
250
+ }
251
+ ]
252
+ }
231
253
  expected = HashWithIndifferentAccess.new({
232
254
  shipments: [
233
255
  HashWithIndifferentAccess.new({
@@ -238,60 +260,63 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
238
260
  })
239
261
  ]
240
262
  })
241
- actual = {
242
- shipments: [
243
- {
244
- estimated_delivery: {
245
- from: '2019-05-06',
246
- to: '2019-05-09'
247
- }
248
- }
249
- ]
250
- }
251
263
  expect(actual).to eq(expected)
252
264
  TEST
253
265
  program = make_program(snippet, color_enabled: color_enabled)
254
266
 
255
- expected_output = build_expected_output(
256
- color_enabled: color_enabled,
257
- snippet: "expect(actual).to eq(expected)",
258
- expectation: proc {
259
- line do
260
- plain %|Expected |
261
- actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
262
- end
263
-
264
- line do
265
- plain %| to eq |
266
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
267
- end
268
- },
269
- diff: proc {
270
- plain_line %| #<HashWithIndifferentAccess {|
271
- plain_line %| "shipments" => [|
272
- plain_line %| #<HashWithIndifferentAccess {|
273
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
274
- plain_line %| "from" => "2019-05-06",|
275
- expected_line %|- "to" => "2019-05-06"|
276
- actual_line %|+ "to" => "2019-05-09"|
277
- plain_line %| }>|
278
- plain_line %| }>|
279
- plain_line %| ]|
280
- plain_line %| }>|
281
- },
282
- )
283
-
284
- expect(program).
285
- to produce_output_when_run(expected_output).
286
- in_color(color_enabled)
267
+ expected_output =
268
+ build_expected_output(
269
+ color_enabled: color_enabled,
270
+ snippet: "expect(actual).to eq(expected)",
271
+ expectation:
272
+ proc do
273
+ line do
274
+ plain "Expected "
275
+ actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
276
+ end
277
+
278
+ line do
279
+ plain " to eq "
280
+ expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
281
+ end
282
+ end,
283
+ diff:
284
+ proc do
285
+ plain_line " #<HashWithIndifferentAccess {"
286
+ plain_line %| "shipments" => [|
287
+ plain_line " #<HashWithIndifferentAccess {"
288
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
289
+ plain_line %| "from" => "2019-05-06",|
290
+ expected_line %|- "to" => "2019-05-06"|
291
+ actual_line %|+ "to" => "2019-05-09"|
292
+ plain_line " }>"
293
+ plain_line " }>"
294
+ plain_line " ]"
295
+ plain_line " }>"
296
+ end
297
+ )
298
+
299
+ expect(program).to produce_output_when_run(
300
+ expected_output
301
+ ).in_color(color_enabled)
287
302
  end
288
303
  end
289
304
  end
290
305
 
291
- context "and the actual hash contains string keys" do
306
+ context "and the actual hash contains string keys" do
292
307
  it "produces the correct output" do
293
308
  as_both_colored_and_uncolored do |color_enabled|
294
309
  snippet = <<~TEST.strip
310
+ actual = {
311
+ 'shipments' => [
312
+ {
313
+ 'estimated_delivery' => {
314
+ 'from' => '2019-05-06',
315
+ 'to' => '2019-05-09'
316
+ }
317
+ }
318
+ ]
319
+ }
295
320
  expected = HashWithIndifferentAccess.new({
296
321
  shipments: [
297
322
  HashWithIndifferentAccess.new({
@@ -302,52 +327,45 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
302
327
  })
303
328
  ]
304
329
  })
305
- actual = {
306
- 'shipments' => [
307
- {
308
- 'estimated_delivery' => {
309
- 'from' => '2019-05-06',
310
- 'to' => '2019-05-09'
311
- }
312
- }
313
- ]
314
- }
315
330
  expect(actual).to eq(expected)
316
331
  TEST
317
332
  program = make_program(snippet, color_enabled: color_enabled)
318
333
 
319
- expected_output = build_expected_output(
320
- color_enabled: color_enabled,
321
- snippet: "expect(actual).to eq(expected)",
322
- expectation: proc {
323
- line do
324
- plain %|Expected |
325
- actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
326
- end
327
-
328
- line do
329
- plain %| to eq |
330
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
331
- end
332
- },
333
- diff: proc {
334
- plain_line %| #<HashWithIndifferentAccess {|
335
- plain_line %| "shipments" => [|
336
- plain_line %| #<HashWithIndifferentAccess {|
337
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
338
- plain_line %| "from" => "2019-05-06",|
339
- expected_line %|- "to" => "2019-05-06"|
340
- actual_line %|+ "to" => "2019-05-09"|
341
- plain_line %| }>|
342
- plain_line %| }>|
343
- plain_line %| ]|
344
- plain_line %| }>|
345
- },
346
- )
347
-
348
- expect(program).
349
- to produce_output_when_run(expected_output).
350
- in_color(color_enabled)
334
+ expected_output =
335
+ build_expected_output(
336
+ color_enabled: color_enabled,
337
+ snippet: "expect(actual).to eq(expected)",
338
+ expectation:
339
+ proc do
340
+ line do
341
+ plain "Expected "
342
+ actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
343
+ end
344
+
345
+ line do
346
+ plain " to eq "
347
+ expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
348
+ end
349
+ end,
350
+ diff:
351
+ proc do
352
+ plain_line " #<HashWithIndifferentAccess {"
353
+ plain_line %| "shipments" => [|
354
+ plain_line " #<HashWithIndifferentAccess {"
355
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
356
+ plain_line %| "from" => "2019-05-06",|
357
+ expected_line %|- "to" => "2019-05-06"|
358
+ actual_line %|+ "to" => "2019-05-09"|
359
+ plain_line " }>"
360
+ plain_line " }>"
361
+ plain_line " ]"
362
+ plain_line " }>"
363
+ end
364
+ )
365
+
366
+ expect(program).to produce_output_when_run(
367
+ expected_output
368
+ ).in_color(color_enabled)
351
369
  end
352
370
  end
353
371
  end
@@ -356,58 +374,61 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
356
374
  end
357
375
 
358
376
  describe "and RSpec's #match matcher" do
359
- context "when the actual value is a HashWithIndifferentAccess" do
377
+ context "when the actual value is a HashWithIndifferentAccess" do
360
378
  context "and both hashes are one-dimensional" do
361
379
  context "and the expected hash contains symbol keys" do
362
380
  it "produces the correct output" do
363
381
  as_both_colored_and_uncolored do |color_enabled|
364
382
  snippet = <<~TEST.strip
383
+ actual = HashWithIndifferentAccess.new({
384
+ line_1: "456 Ponderosa Ct.",
385
+ city: "Oakland",
386
+ state: "CA",
387
+ zip: "91234",
388
+ })
365
389
  expected = {
366
390
  line_1: "123 Main St.",
367
391
  city: "Hill Valley",
368
392
  state: "CA",
369
393
  zip: "90382",
370
394
  }
371
- actual = HashWithIndifferentAccess.new({
372
- line_1: "456 Ponderosa Ct.",
373
- city: "Oakland",
374
- state: "CA",
375
- zip: "91234",
376
- })
377
395
  expect(actual).to match(expected)
378
396
  TEST
379
397
  program = make_program(snippet, color_enabled: color_enabled)
380
398
 
381
- expected_output = build_expected_output(
382
- color_enabled: color_enabled,
383
- snippet: "expect(actual).to match(expected)",
384
- expectation: proc {
385
- line do
386
- plain %|Expected |
387
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
388
- end
389
-
390
- line do
391
- plain %|to match |
392
- expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
393
- end
394
- },
395
- diff: proc {
396
- plain_line %| #<HashWithIndifferentAccess {|
397
- expected_line %|- "line_1" => "123 Main St.",|
398
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
399
- expected_line %|- "city" => "Hill Valley",|
400
- actual_line %|+ "city" => "Oakland",|
401
- plain_line %| "state" => "CA",|
402
- expected_line %|- "zip" => "90382"|
403
- actual_line %|+ "zip" => "91234"|
404
- plain_line %| }>|
405
- },
406
- )
407
-
408
- expect(program).
409
- to produce_output_when_run(expected_output).
410
- in_color(color_enabled)
399
+ expected_output =
400
+ build_expected_output(
401
+ color_enabled: color_enabled,
402
+ snippet: "expect(actual).to match(expected)",
403
+ expectation:
404
+ proc do
405
+ line do
406
+ plain "Expected "
407
+ actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
408
+ end
409
+
410
+ line do
411
+ plain "to match "
412
+ expected %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
413
+ end
414
+ end,
415
+ diff:
416
+ proc do
417
+ plain_line " #<HashWithIndifferentAccess {"
418
+ expected_line %|- "line_1" => "123 Main St.",|
419
+ actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
420
+ expected_line %|- "city" => "Hill Valley",|
421
+ actual_line %|+ "city" => "Oakland",|
422
+ plain_line %| "state" => "CA",|
423
+ expected_line %|- "zip" => "90382"|
424
+ actual_line %|+ "zip" => "91234"|
425
+ plain_line " }>"
426
+ end
427
+ )
428
+
429
+ expect(program).to produce_output_when_run(
430
+ expected_output
431
+ ).in_color(color_enabled)
411
432
  end
412
433
  end
413
434
  end
@@ -416,52 +437,55 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
416
437
  it "produces the correct output" do
417
438
  as_both_colored_and_uncolored do |color_enabled|
418
439
  snippet = <<~TEST.strip
440
+ actual = HashWithIndifferentAccess.new({
441
+ line_1: "456 Ponderosa Ct.",
442
+ city: "Oakland",
443
+ state: "CA",
444
+ zip: "91234",
445
+ })
419
446
  expected = {
420
447
  "line_1" => "123 Main St.",
421
448
  "city" => "Hill Valley",
422
449
  "state" => "CA",
423
450
  "zip" => "90382",
424
451
  }
425
- actual = HashWithIndifferentAccess.new({
426
- line_1: "456 Ponderosa Ct.",
427
- city: "Oakland",
428
- state: "CA",
429
- zip: "91234",
430
- })
431
452
  expect(actual).to match(expected)
432
453
  TEST
433
454
  program = make_program(snippet, color_enabled: color_enabled)
434
455
 
435
- expected_output = build_expected_output(
436
- color_enabled: color_enabled,
437
- snippet: "expect(actual).to match(expected)",
438
- expectation: proc {
439
- line do
440
- plain %|Expected |
441
- actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
442
- end
443
-
444
- line do
445
- plain %|to match |
446
- expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
447
- end
448
- },
449
- diff: proc {
450
- plain_line %| #<HashWithIndifferentAccess {|
451
- expected_line %|- "line_1" => "123 Main St.",|
452
- actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
453
- expected_line %|- "city" => "Hill Valley",|
454
- actual_line %|+ "city" => "Oakland",|
455
- plain_line %| "state" => "CA",|
456
- expected_line %|- "zip" => "90382"|
457
- actual_line %|+ "zip" => "91234"|
458
- plain_line %| }>|
459
- },
460
- )
461
-
462
- expect(program).
463
- to produce_output_when_run(expected_output).
464
- in_color(color_enabled)
456
+ expected_output =
457
+ build_expected_output(
458
+ color_enabled: color_enabled,
459
+ snippet: "expect(actual).to match(expected)",
460
+ expectation:
461
+ proc do
462
+ line do
463
+ plain "Expected "
464
+ actual %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
465
+ end
466
+
467
+ line do
468
+ plain "to match "
469
+ expected %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
470
+ end
471
+ end,
472
+ diff:
473
+ proc do
474
+ plain_line " #<HashWithIndifferentAccess {"
475
+ expected_line %|- "line_1" => "123 Main St.",|
476
+ actual_line %|+ "line_1" => "456 Ponderosa Ct.",|
477
+ expected_line %|- "city" => "Hill Valley",|
478
+ actual_line %|+ "city" => "Oakland",|
479
+ plain_line %| "state" => "CA",|
480
+ expected_line %|- "zip" => "90382"|
481
+ actual_line %|+ "zip" => "91234"|
482
+ plain_line " }>"
483
+ end
484
+ )
485
+
486
+ expect(program).to produce_output_when_run(
487
+ expected_output
488
+ ).in_color(color_enabled)
465
489
  end
466
490
  end
467
491
  end
@@ -470,120 +494,136 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
470
494
 
471
495
  context "when the expected value is a HashWithIndifferentAccess" do
472
496
  context "and both hashes are one-dimensional" do
473
- context "and the actual hash contains symbol keys" do
497
+ context "and the actual hash contains symbol keys" do
474
498
  it "produces the correct output" do
475
499
  as_both_colored_and_uncolored do |color_enabled|
476
500
  snippet = <<~TEST.strip
501
+ actual = {
502
+ line_1: "123 Main St.",
503
+ city: "Hill Valley",
504
+ state: "CA",
505
+ zip: "90382",
506
+ }
477
507
  expected = HashWithIndifferentAccess.new({
478
508
  line_1: "456 Ponderosa Ct.",
479
509
  city: "Oakland",
480
510
  state: "CA",
481
511
  zip: "91234",
482
512
  })
483
- actual = {
484
- line_1: "123 Main St.",
485
- city: "Hill Valley",
486
- state: "CA",
487
- zip: "90382",
488
- }
489
513
  expect(actual).to match(expected)
490
514
  TEST
491
515
  program = make_program(snippet, color_enabled: color_enabled)
492
516
 
493
- expected_output = build_expected_output(
494
- color_enabled: color_enabled,
495
- snippet: "expect(actual).to match(expected)",
496
- expectation: proc {
497
- line do
498
- plain %|Expected |
499
- actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
500
- end
501
-
502
- line do
503
- plain %|to match |
504
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
505
- end
506
- },
507
- diff: proc {
508
- plain_line %| #<HashWithIndifferentAccess {|
509
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
510
- actual_line %|+ "line_1" => "123 Main St.",|
511
- expected_line %|- "city" => "Oakland",|
512
- actual_line %|+ "city" => "Hill Valley",|
513
- plain_line %| "state" => "CA",|
514
- expected_line %|- "zip" => "91234"|
515
- actual_line %|+ "zip" => "90382"|
516
- plain_line %| }>|
517
- },
518
- )
519
-
520
- expect(program).
521
- to produce_output_when_run(expected_output).
522
- in_color(color_enabled)
517
+ expected_output =
518
+ build_expected_output(
519
+ color_enabled: color_enabled,
520
+ snippet: "expect(actual).to match(expected)",
521
+ expectation:
522
+ proc do
523
+ line do
524
+ plain "Expected "
525
+ actual %|{ line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" }|
526
+ end
527
+
528
+ line do
529
+ plain "to match "
530
+ expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
531
+ end
532
+ end,
533
+ diff:
534
+ proc do
535
+ plain_line " #<HashWithIndifferentAccess {"
536
+ expected_line %|- "line_1" => "456 Ponderosa Ct.",|
537
+ actual_line %|+ "line_1" => "123 Main St.",|
538
+ expected_line %|- "city" => "Oakland",|
539
+ actual_line %|+ "city" => "Hill Valley",|
540
+ plain_line %| "state" => "CA",|
541
+ expected_line %|- "zip" => "91234"|
542
+ actual_line %|+ "zip" => "90382"|
543
+ plain_line " }>"
544
+ end
545
+ )
546
+
547
+ expect(program).to produce_output_when_run(
548
+ expected_output
549
+ ).in_color(color_enabled)
523
550
  end
524
551
  end
525
552
  end
526
553
 
527
- context "and the actual hash contains string keys" do
554
+ context "and the actual hash contains string keys" do
528
555
  it "produces the correct output" do
529
556
  as_both_colored_and_uncolored do |color_enabled|
530
557
  snippet = <<~TEST.strip
558
+ actual = {
559
+ "line_1" => "123 Main St.",
560
+ "city" => "Hill Valley",
561
+ "state" => "CA",
562
+ "zip" => "90382",
563
+ }
531
564
  expected = HashWithIndifferentAccess.new({
532
565
  line_1: "456 Ponderosa Ct.",
533
566
  city: "Oakland",
534
567
  state: "CA",
535
568
  zip: "91234",
536
569
  })
537
- actual = {
538
- "line_1" => "123 Main St.",
539
- "city" => "Hill Valley",
540
- "state" => "CA",
541
- "zip" => "90382",
542
- }
543
570
  expect(actual).to match(expected)
544
571
  TEST
545
572
  program = make_program(snippet, color_enabled: color_enabled)
546
573
 
547
- expected_output = build_expected_output(
548
- color_enabled: color_enabled,
549
- snippet: "expect(actual).to match(expected)",
550
- expectation: proc {
551
- line do
552
- plain %|Expected |
553
- actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
554
- end
555
-
556
- line do
557
- plain %|to match |
558
- expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
559
- end
560
- },
561
- diff: proc {
562
- plain_line %| #<HashWithIndifferentAccess {|
563
- expected_line %|- "line_1" => "456 Ponderosa Ct.",|
564
- actual_line %|+ "line_1" => "123 Main St.",|
565
- expected_line %|- "city" => "Oakland",|
566
- actual_line %|+ "city" => "Hill Valley",|
567
- plain_line %| "state" => "CA",|
568
- expected_line %|- "zip" => "91234"|
569
- actual_line %|+ "zip" => "90382"|
570
- plain_line %| }>|
571
- },
572
- )
573
-
574
- expect(program).
575
- to produce_output_when_run(expected_output).
576
- in_color(color_enabled)
574
+ expected_output =
575
+ build_expected_output(
576
+ color_enabled: color_enabled,
577
+ snippet: "expect(actual).to match(expected)",
578
+ expectation:
579
+ proc do
580
+ line do
581
+ plain "Expected "
582
+ actual %|{ "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }|
583
+ end
584
+
585
+ line do
586
+ plain "to match "
587
+ expected %|#<HashWithIndifferentAccess { "line_1" => "456 Ponderosa Ct.", "city" => "Oakland", "state" => "CA", "zip" => "91234" }>|
588
+ end
589
+ end,
590
+ diff:
591
+ proc do
592
+ plain_line " #<HashWithIndifferentAccess {"
593
+ expected_line %|- "line_1" => "456 Ponderosa Ct.",|
594
+ actual_line %|+ "line_1" => "123 Main St.",|
595
+ expected_line %|- "city" => "Oakland",|
596
+ actual_line %|+ "city" => "Hill Valley",|
597
+ plain_line %| "state" => "CA",|
598
+ expected_line %|- "zip" => "91234"|
599
+ actual_line %|+ "zip" => "90382"|
600
+ plain_line " }>"
601
+ end
602
+ )
603
+
604
+ expect(program).to produce_output_when_run(
605
+ expected_output
606
+ ).in_color(color_enabled)
577
607
  end
578
608
  end
579
609
  end
580
610
  end
581
611
 
582
612
  context "and both hashes are multi-dimensional" do
583
- context "and the actual hash contains symbol keys" do
613
+ context "and the actual hash contains symbol keys" do
584
614
  it "produces the correct output" do
585
615
  as_both_colored_and_uncolored do |color_enabled|
586
616
  snippet = <<~TEST.strip
617
+ actual = {
618
+ shipments: [
619
+ {
620
+ estimated_delivery: {
621
+ from: '2019-05-06',
622
+ to: '2019-05-09'
623
+ }
624
+ }
625
+ ]
626
+ }
587
627
  expected = HashWithIndifferentAccess.new({
588
628
  shipments: [
589
629
  HashWithIndifferentAccess.new({
@@ -594,60 +634,63 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
594
634
  })
595
635
  ]
596
636
  })
597
- actual = {
598
- shipments: [
599
- {
600
- estimated_delivery: {
601
- from: '2019-05-06',
602
- to: '2019-05-09'
603
- }
604
- }
605
- ]
606
- }
607
637
  expect(actual).to match(expected)
608
638
  TEST
609
639
  program = make_program(snippet, color_enabled: color_enabled)
610
640
 
611
- expected_output = build_expected_output(
612
- color_enabled: color_enabled,
613
- snippet: "expect(actual).to match(expected)",
614
- expectation: proc {
615
- line do
616
- plain %|Expected |
617
- actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
618
- end
619
-
620
- line do
621
- plain %|to match |
622
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
623
- end
624
- },
625
- diff: proc {
626
- plain_line %| #<HashWithIndifferentAccess {|
627
- plain_line %| "shipments" => [|
628
- plain_line %| #<HashWithIndifferentAccess {|
629
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
630
- plain_line %| "from" => "2019-05-06",|
631
- expected_line %|- "to" => "2019-05-06"|
632
- actual_line %|+ "to" => "2019-05-09"|
633
- plain_line %| }>|
634
- plain_line %| }>|
635
- plain_line %| ]|
636
- plain_line %| }>|
637
- },
638
- )
639
-
640
- expect(program).
641
- to produce_output_when_run(expected_output).
642
- in_color(color_enabled)
641
+ expected_output =
642
+ build_expected_output(
643
+ color_enabled: color_enabled,
644
+ snippet: "expect(actual).to match(expected)",
645
+ expectation:
646
+ proc do
647
+ line do
648
+ plain "Expected "
649
+ actual %|{ shipments: [{ estimated_delivery: { from: "2019-05-06", to: "2019-05-09" } }] }|
650
+ end
651
+
652
+ line do
653
+ plain "to match "
654
+ expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
655
+ end
656
+ end,
657
+ diff:
658
+ proc do
659
+ plain_line " #<HashWithIndifferentAccess {"
660
+ plain_line %| "shipments" => [|
661
+ plain_line " #<HashWithIndifferentAccess {"
662
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
663
+ plain_line %| "from" => "2019-05-06",|
664
+ expected_line %|- "to" => "2019-05-06"|
665
+ actual_line %|+ "to" => "2019-05-09"|
666
+ plain_line " }>"
667
+ plain_line " }>"
668
+ plain_line " ]"
669
+ plain_line " }>"
670
+ end
671
+ )
672
+
673
+ expect(program).to produce_output_when_run(
674
+ expected_output
675
+ ).in_color(color_enabled)
643
676
  end
644
677
  end
645
678
  end
646
679
 
647
- context "and the actual hash contains string keys" do
680
+ context "and the actual hash contains string keys" do
648
681
  it "produces the correct output" do
649
682
  as_both_colored_and_uncolored do |color_enabled|
650
683
  snippet = <<~TEST.strip
684
+ actual = {
685
+ 'shipments' => [
686
+ {
687
+ 'estimated_delivery' => {
688
+ 'from' => '2019-05-06',
689
+ 'to' => '2019-05-09'
690
+ }
691
+ }
692
+ ]
693
+ }
651
694
  expected = HashWithIndifferentAccess.new({
652
695
  shipments: [
653
696
  HashWithIndifferentAccess.new({
@@ -658,52 +701,45 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
658
701
  })
659
702
  ]
660
703
  })
661
- actual = {
662
- 'shipments' => [
663
- {
664
- 'estimated_delivery' => {
665
- 'from' => '2019-05-06',
666
- 'to' => '2019-05-09'
667
- }
668
- }
669
- ]
670
- }
671
704
  expect(actual).to match(expected)
672
705
  TEST
673
706
  program = make_program(snippet, color_enabled: color_enabled)
674
707
 
675
- expected_output = build_expected_output(
676
- color_enabled: color_enabled,
677
- snippet: "expect(actual).to match(expected)",
678
- expectation: proc {
679
- line do
680
- plain %|Expected |
681
- actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
682
- end
683
-
684
- line do
685
- plain %|to match |
686
- expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
687
- end
688
- },
689
- diff: proc {
690
- plain_line %| #<HashWithIndifferentAccess {|
691
- plain_line %| "shipments" => [|
692
- plain_line %| #<HashWithIndifferentAccess {|
693
- plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
694
- plain_line %| "from" => "2019-05-06",|
695
- expected_line %|- "to" => "2019-05-06"|
696
- actual_line %|+ "to" => "2019-05-09"|
697
- plain_line %| }>|
698
- plain_line %| }>|
699
- plain_line %| ]|
700
- plain_line %| }>|
701
- },
702
- )
703
-
704
- expect(program).
705
- to produce_output_when_run(expected_output).
706
- in_color(color_enabled)
708
+ expected_output =
709
+ build_expected_output(
710
+ color_enabled: color_enabled,
711
+ snippet: "expect(actual).to match(expected)",
712
+ expectation:
713
+ proc do
714
+ line do
715
+ plain "Expected "
716
+ actual %|{ "shipments" => [{ "estimated_delivery" => { "from" => "2019-05-06", "to" => "2019-05-09" } }] }|
717
+ end
718
+
719
+ line do
720
+ plain "to match "
721
+ expected %|#<HashWithIndifferentAccess { "shipments" => [#<HashWithIndifferentAccess { "estimated_delivery" => #<HashWithIndifferentAccess { "from" => "2019-05-06", "to" => "2019-05-06" }> }>] }>|
722
+ end
723
+ end,
724
+ diff:
725
+ proc do
726
+ plain_line " #<HashWithIndifferentAccess {"
727
+ plain_line %| "shipments" => [|
728
+ plain_line " #<HashWithIndifferentAccess {"
729
+ plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
730
+ plain_line %| "from" => "2019-05-06",|
731
+ expected_line %|- "to" => "2019-05-06"|
732
+ actual_line %|+ "to" => "2019-05-09"|
733
+ plain_line " }>"
734
+ plain_line " }>"
735
+ plain_line " ]"
736
+ plain_line " }>"
737
+ end
738
+ )
739
+
740
+ expect(program).to produce_output_when_run(
741
+ expected_output
742
+ ).in_color(color_enabled)
707
743
  end
708
744
  end
709
745
  end