super_diff 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) 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 +5 -13
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
  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 +3 -9
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
  19. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  20. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  21. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  22. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  23. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  24. data/lib/super_diff/active_support.rb +6 -11
  25. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  26. data/lib/super_diff/configuration.rb +14 -8
  27. data/lib/super_diff/csi/color.rb +4 -4
  28. data/lib/super_diff/csi/colorized_document.rb +12 -16
  29. data/lib/super_diff/csi/document.rb +8 -19
  30. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  31. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  32. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  33. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  34. data/lib/super_diff/csi.rb +10 -14
  35. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  36. data/lib/super_diff/differs/default_object.rb +1 -1
  37. data/lib/super_diff/differs/defaults.rb +1 -1
  38. data/lib/super_diff/differs/main.rb +2 -13
  39. data/lib/super_diff/equality_matchers/array.rb +10 -12
  40. data/lib/super_diff/equality_matchers/base.rb +1 -1
  41. data/lib/super_diff/equality_matchers/default.rb +2 -4
  42. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  43. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  44. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  45. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  46. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  47. data/lib/super_diff/equality_matchers.rb +1 -1
  48. data/lib/super_diff/errors.rb +3 -3
  49. data/lib/super_diff/gem_version.rb +3 -3
  50. data/lib/super_diff/helpers.rb +10 -10
  51. data/lib/super_diff/implementation_checks.rb +2 -2
  52. data/lib/super_diff/line.rb +3 -3
  53. data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
  54. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
  55. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
  56. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
  60. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
  61. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
  62. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  63. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  64. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  65. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  66. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  67. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  68. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  69. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  70. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  71. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  72. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  74. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  75. data/lib/super_diff/object_inspection.rb +3 -3
  76. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  77. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  78. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  79. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  80. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  81. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  82. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  83. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  84. data/lib/super_diff/operation_tree_builders.rb +1 -1
  85. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  86. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  87. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  88. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  89. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  90. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  91. data/lib/super_diff/operation_trees/base.rb +3 -5
  92. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  93. data/lib/super_diff/operations/binary_operation.rb +2 -2
  94. data/lib/super_diff/operations/unary_operation.rb +1 -1
  95. data/lib/super_diff/rails.rb +2 -1
  96. data/lib/super_diff/recursion_guard.rb +5 -4
  97. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  98. data/lib/super_diff/rspec/differ.rb +6 -13
  99. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  100. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  101. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  102. data/lib/super_diff/rspec/differs.rb +3 -3
  103. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  104. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  105. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  106. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
  107. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  108. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  109. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  110. data/lib/super_diff/rspec/monkey_patches.rb +122 -116
  111. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
  112. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
  113. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
  114. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
  115. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
  116. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
  117. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  118. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  119. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  120. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  121. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  122. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  123. data/lib/super_diff/rspec.rb +11 -13
  124. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  125. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  126. data/lib/super_diff/version.rb +1 -1
  127. data/lib/super_diff.rb +4 -9
  128. data/spec/examples.txt +493 -485
  129. data/spec/integration/rails/active_record_spec.rb +3 -1
  130. data/spec/integration/rails/engines_spec.rb +20 -0
  131. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  132. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  133. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  134. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  135. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  136. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  137. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
  138. data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
  139. data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
  140. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  141. data/spec/integration/rspec/include_matcher_spec.rb +317 -215
  142. data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
  143. data/spec/integration/rspec/match_matcher_spec.rb +847 -834
  144. data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
  145. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  146. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  147. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  148. data/spec/spec_helper.rb +17 -20
  149. data/spec/support/command_runner.rb +34 -57
  150. data/spec/support/integration/helpers.rb +35 -28
  151. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  152. data/spec/support/integration/test_programs/base.rb +12 -17
  153. data/spec/support/integration/test_programs/plain.rb +6 -0
  154. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  155. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  156. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  157. data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
  158. data/spec/support/models/active_record/person.rb +6 -4
  159. data/spec/support/models/active_record/shipping_address.rb +9 -10
  160. data/spec/support/models/customer.rb +2 -4
  161. data/spec/support/models/player.rb +3 -6
  162. data/spec/support/models/shipping_address.rb +4 -13
  163. data/spec/support/shared_examples/active_record.rb +232 -214
  164. data/spec/support/shared_examples/active_support.rb +53 -51
  165. data/spec/support/shared_examples/elided_diffs.rb +405 -381
  166. data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
  167. data/spec/support/shared_examples/key.rb +123 -0
  168. data/spec/support/unit/helpers.rb +1 -3
  169. data/spec/support/unit/matchers/match_output.rb +12 -13
  170. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  171. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  172. data/spec/unit/helpers_spec.rb +14 -21
  173. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  174. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  175. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  176. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  177. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  178. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  179. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  180. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  181. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  182. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  183. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  184. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  185. data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
  186. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  187. data/spec/unit/rspec/object_inspection_spec.rb +349 -324
  188. data/spec/unit/super_diff_spec.rb +1542 -1449
  189. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  190. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  191. data/super_diff.gemspec +13 -12
  192. metadata +73 -73
  193. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -7,37 +7,38 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
7
7
  as_both_colored_and_uncolored do |color_enabled|
8
8
  snippet = <<~TEST.strip
9
9
  expected = a_hash_including(city: "Hill Valley")
10
- actual = { city: "Burbank" }
10
+ actual = { city: "Burbank" }
11
11
  expect(actual).to match(expected)
12
12
  TEST
13
- program = make_plain_test_program(
14
- snippet,
15
- color_enabled: color_enabled,
16
- )
13
+ program =
14
+ make_plain_test_program(snippet, color_enabled: color_enabled)
15
+
16
+ expected_output =
17
+ build_expected_output(
18
+ color_enabled: color_enabled,
19
+ snippet: "expect(actual).to match(expected)",
20
+ expectation:
21
+ proc do
22
+ line do
23
+ plain "Expected "
24
+ actual %|{ city: "Burbank" }|
25
+ plain " to match "
26
+ expected %|#<a hash including (city: "Hill Valley")>|
27
+ plain "."
28
+ end
29
+ end,
30
+ diff:
31
+ proc do
32
+ plain_line " {"
33
+ expected_line %|- city: "Hill Valley"|
34
+ actual_line %|+ city: "Burbank"|
35
+ plain_line " }"
36
+ end
37
+ )
17
38
 
18
- expected_output = build_expected_output(
19
- color_enabled: color_enabled,
20
- snippet: %|expect(actual).to match(expected)|,
21
- expectation: proc {
22
- line do
23
- plain %|Expected |
24
- actual %|{ city: "Burbank" }|
25
- plain %| to match |
26
- expected %|#<a hash including (city: "Hill Valley")>|
27
- plain %|.|
28
- end
29
- },
30
- diff: proc {
31
- plain_line %| {|
32
- expected_line %|- city: "Hill Valley"|
33
- actual_line %|+ city: "Burbank"|
34
- plain_line %| }|
35
- },
39
+ expect(program).to produce_output_when_run(expected_output).in_color(
40
+ color_enabled
36
41
  )
37
-
38
- expect(program).
39
- to produce_output_when_run(expected_output).
40
- in_color(color_enabled)
41
42
  end
42
43
  end
43
44
 
@@ -45,31 +46,31 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
45
46
  as_both_colored_and_uncolored do |color_enabled|
46
47
  snippet = <<~TEST.strip
47
48
  expected = a_hash_including(city: "Burbank")
48
- actual = { city: "Burbank" }
49
+ actual = { city: "Burbank" }
49
50
  expect(actual).not_to match(expected)
50
51
  TEST
51
- program = make_plain_test_program(
52
- snippet,
53
- color_enabled: color_enabled,
54
- )
52
+ program =
53
+ make_plain_test_program(snippet, color_enabled: color_enabled)
54
+
55
+ expected_output =
56
+ build_expected_output(
57
+ color_enabled: color_enabled,
58
+ snippet: "expect(actual).not_to match(expected)",
59
+ expectation:
60
+ proc do
61
+ line do
62
+ plain "Expected "
63
+ actual %|{ city: "Burbank" }|
64
+ plain " not to match "
65
+ expected %|#<a hash including (city: "Burbank")>|
66
+ plain "."
67
+ end
68
+ end
69
+ )
55
70
 
56
- expected_output = build_expected_output(
57
- color_enabled: color_enabled,
58
- snippet: %|expect(actual).not_to match(expected)|,
59
- expectation: proc {
60
- line do
61
- plain %|Expected |
62
- actual %|{ city: "Burbank" }|
63
- plain %| not to match |
64
- expected %|#<a hash including (city: "Burbank")>|
65
- plain %|.|
66
- end
67
- },
71
+ expect(program).to produce_output_when_run(expected_output).in_color(
72
+ color_enabled
68
73
  )
69
-
70
- expect(program).
71
- to produce_output_when_run(expected_output).
72
- in_color(color_enabled)
73
74
  end
74
75
  end
75
76
  end
@@ -82,7 +83,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
82
83
  city: "Hill Valley",
83
84
  zip: "90382"
84
85
  )
85
- actual = {
86
+ actual = {
86
87
  line_1: "123 Main St.",
87
88
  city: "Burbank",
88
89
  state: "CA",
@@ -90,40 +91,41 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
90
91
  }
91
92
  expect(actual).to match(expected)
92
93
  TEST
93
- program = make_plain_test_program(
94
- snippet,
95
- color_enabled: color_enabled,
96
- )
97
-
98
- expected_output = build_expected_output(
99
- color_enabled: color_enabled,
100
- snippet: %|expect(actual).to match(expected)|,
101
- expectation: proc {
102
- line do
103
- plain %|Expected |
104
- actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
105
- end
94
+ program =
95
+ make_plain_test_program(snippet, color_enabled: color_enabled)
96
+
97
+ expected_output =
98
+ build_expected_output(
99
+ color_enabled: color_enabled,
100
+ snippet: "expect(actual).to match(expected)",
101
+ expectation:
102
+ proc do
103
+ line do
104
+ plain "Expected "
105
+ actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
106
+ end
107
+
108
+ line do
109
+ plain "to match "
110
+ expected %|#<a hash including (city: "Hill Valley", zip: "90382")>|
111
+ end
112
+ end,
113
+ diff:
114
+ proc do
115
+ plain_line " {"
116
+ plain_line %| line_1: "123 Main St.",|
117
+ expected_line %|- city: "Hill Valley",|
118
+ actual_line %|+ city: "Burbank",|
119
+ plain_line %| state: "CA",|
120
+ expected_line %|- zip: "90382"|
121
+ actual_line %|+ zip: "90210"|
122
+ plain_line " }"
123
+ end
124
+ )
106
125
 
107
- line do
108
- plain %|to match |
109
- expected %|#<a hash including (city: "Hill Valley", zip: "90382")>|
110
- end
111
- },
112
- diff: proc {
113
- plain_line %| {|
114
- plain_line %| line_1: "123 Main St.",|
115
- expected_line %|- city: "Hill Valley",|
116
- actual_line %|+ city: "Burbank",|
117
- plain_line %| state: "CA",|
118
- expected_line %|- zip: "90382"|
119
- actual_line %|+ zip: "90210"|
120
- plain_line %| }|
121
- },
126
+ expect(program).to produce_output_when_run(expected_output).in_color(
127
+ color_enabled
122
128
  )
123
-
124
- expect(program).
125
- to produce_output_when_run(expected_output).
126
- in_color(color_enabled)
127
129
  end
128
130
  end
129
131
 
@@ -134,7 +136,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
134
136
  city: "Burbank",
135
137
  zip: "90210"
136
138
  )
137
- actual = {
139
+ actual = {
138
140
  line_1: "123 Main St.",
139
141
  city: "Burbank",
140
142
  state: "CA",
@@ -142,38 +144,38 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
142
144
  }
143
145
  expect(actual).not_to match(expected)
144
146
  TEST
145
- program = make_plain_test_program(
146
- snippet,
147
- color_enabled: color_enabled,
148
- )
149
-
150
- expected_output = build_expected_output(
151
- color_enabled: color_enabled,
152
- snippet: %|expect(actual).not_to match(expected)|,
153
- newline_before_expectation: true,
154
- expectation: proc {
155
- line do
156
- plain %| Expected |
157
- actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
158
- end
147
+ program =
148
+ make_plain_test_program(snippet, color_enabled: color_enabled)
149
+
150
+ expected_output =
151
+ build_expected_output(
152
+ color_enabled: color_enabled,
153
+ snippet: "expect(actual).not_to match(expected)",
154
+ newline_before_expectation: true,
155
+ expectation:
156
+ proc do
157
+ line do
158
+ plain " Expected "
159
+ actual %|{ line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" }|
160
+ end
161
+
162
+ line do
163
+ plain "not to match "
164
+ expected %|#<a hash including (city: "Burbank", zip: "90210")>|
165
+ end
166
+ end
167
+ )
159
168
 
160
- line do
161
- plain %|not to match |
162
- expected %|#<a hash including (city: "Burbank", zip: "90210")>|
163
- end
164
- },
169
+ expect(program).to produce_output_when_run(expected_output).in_color(
170
+ color_enabled
165
171
  )
166
-
167
- expect(program).
168
- to produce_output_when_run(expected_output).
169
- in_color(color_enabled)
170
172
  end
171
173
  end
172
174
  end
173
175
  end
174
176
 
175
177
  context "when the expected value includes a hash-including-<something>" do
176
- context "and the corresponding actual value is a hash" do
178
+ context "and the corresponding actual value is a hash" do
177
179
  it "produces the correct failure message when used in the positive" do
178
180
  as_both_colored_and_uncolored do |color_enabled|
179
181
  snippet = <<~TEST.strip
@@ -184,7 +186,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
184
186
  zip: "90382"
185
187
  )
186
188
  }
187
- actual = {
189
+ actual = {
188
190
  name: "Marty McFly",
189
191
  address: {
190
192
  line_1: "123 Main St.",
@@ -195,43 +197,44 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
195
197
  }
196
198
  expect(actual).to match(expected)
197
199
  TEST
198
- program = make_plain_test_program(
199
- snippet,
200
- color_enabled: color_enabled,
201
- )
202
-
203
- expected_output = build_expected_output(
204
- color_enabled: color_enabled,
205
- snippet: %|expect(actual).to match(expected)|,
206
- expectation: proc {
207
- line do
208
- plain %|Expected |
209
- actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
210
- end
200
+ program =
201
+ make_plain_test_program(snippet, color_enabled: color_enabled)
202
+
203
+ expected_output =
204
+ build_expected_output(
205
+ color_enabled: color_enabled,
206
+ snippet: "expect(actual).to match(expected)",
207
+ expectation:
208
+ proc do
209
+ line do
210
+ plain "Expected "
211
+ actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
212
+ end
213
+
214
+ line do
215
+ plain "to match "
216
+ expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
217
+ end
218
+ end,
219
+ diff:
220
+ proc do
221
+ plain_line " {"
222
+ plain_line %| name: "Marty McFly",|
223
+ plain_line " address: {"
224
+ plain_line %| line_1: "123 Main St.",|
225
+ expected_line %|- city: "Hill Valley",|
226
+ actual_line %|+ city: "Burbank",|
227
+ plain_line %| state: "CA",|
228
+ expected_line %|- zip: "90382"|
229
+ actual_line %|+ zip: "90210"|
230
+ plain_line " }"
231
+ plain_line " }"
232
+ end
233
+ )
211
234
 
212
- line do
213
- plain %|to match |
214
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
215
- end
216
- },
217
- diff: proc {
218
- plain_line %| {|
219
- plain_line %| name: "Marty McFly",|
220
- plain_line %| address: {|
221
- plain_line %| line_1: "123 Main St.",|
222
- expected_line %|- city: "Hill Valley",|
223
- actual_line %|+ city: "Burbank",|
224
- plain_line %| state: "CA",|
225
- expected_line %|- zip: "90382"|
226
- actual_line %|+ zip: "90210"|
227
- plain_line %| }|
228
- plain_line %| }|
229
- },
235
+ expect(program).to produce_output_when_run(expected_output).in_color(
236
+ color_enabled
230
237
  )
231
-
232
- expect(program).
233
- to produce_output_when_run(expected_output).
234
- in_color(color_enabled)
235
238
  end
236
239
  end
237
240
 
@@ -245,7 +248,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
245
248
  zip: "90210"
246
249
  )
247
250
  }
248
- actual = {
251
+ actual = {
249
252
  name: "Marty McFly",
250
253
  address: {
251
254
  line_1: "123 Main St.",
@@ -256,36 +259,36 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
256
259
  }
257
260
  expect(actual).not_to match(expected)
258
261
  TEST
259
- program = make_plain_test_program(
260
- snippet,
261
- color_enabled: color_enabled,
262
- )
263
-
264
- expected_output = build_expected_output(
265
- color_enabled: color_enabled,
266
- snippet: %|expect(actual).not_to match(expected)|,
267
- newline_before_expectation: true,
268
- expectation: proc {
269
- line do
270
- plain %| Expected |
271
- actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
272
- end
262
+ program =
263
+ make_plain_test_program(snippet, color_enabled: color_enabled)
264
+
265
+ expected_output =
266
+ build_expected_output(
267
+ color_enabled: color_enabled,
268
+ snippet: "expect(actual).not_to match(expected)",
269
+ newline_before_expectation: true,
270
+ expectation:
271
+ proc do
272
+ line do
273
+ plain " Expected "
274
+ actual %|{ name: "Marty McFly", address: { line_1: "123 Main St.", city: "Burbank", state: "CA", zip: "90210" } }|
275
+ end
276
+
277
+ line do
278
+ plain "not to match "
279
+ expected %|{ name: "Marty McFly", address: #<a hash including (city: "Burbank", zip: "90210")> }|
280
+ end
281
+ end
282
+ )
273
283
 
274
- line do
275
- plain %|not to match |
276
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Burbank", zip: "90210")> }|
277
- end
278
- },
284
+ expect(program).to produce_output_when_run(expected_output).in_color(
285
+ color_enabled
279
286
  )
280
-
281
- expect(program).
282
- to produce_output_when_run(expected_output).
283
- in_color(color_enabled)
284
287
  end
285
288
  end
286
289
  end
287
290
 
288
- context "and the corresponding actual value is not a hash" do
291
+ context "and the corresponding actual value is not a hash" do
289
292
  it "produces the correct failure message" do
290
293
  as_both_colored_and_uncolored do |color_enabled|
291
294
  snippet = <<~TEST.strip
@@ -296,46 +299,47 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
296
299
  zip: "90382"
297
300
  )
298
301
  }
299
- actual = {
302
+ actual = {
300
303
  name: "Marty McFly",
301
304
  address: nil
302
305
  }
303
306
  expect(actual).to match(expected)
304
307
  TEST
305
- program = make_plain_test_program(
306
- snippet,
307
- color_enabled: color_enabled,
308
- )
309
-
310
- expected_output = build_expected_output(
311
- color_enabled: color_enabled,
312
- snippet: %|expect(actual).to match(expected)|,
313
- expectation: proc {
314
- line do
315
- plain %|Expected |
316
- actual %|{ name: "Marty McFly", address: nil }|
317
- end
308
+ program =
309
+ make_plain_test_program(snippet, color_enabled: color_enabled)
310
+
311
+ expected_output =
312
+ build_expected_output(
313
+ color_enabled: color_enabled,
314
+ snippet: "expect(actual).to match(expected)",
315
+ expectation:
316
+ proc do
317
+ line do
318
+ plain "Expected "
319
+ actual %|{ name: "Marty McFly", address: nil }|
320
+ end
321
+
322
+ line do
323
+ plain "to match "
324
+ expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
325
+ end
326
+ end,
327
+ diff:
328
+ proc do
329
+ plain_line " {"
330
+ plain_line %! name: "Marty McFly",!
331
+ expected_line "- address: #<a hash including ("
332
+ expected_line %!- city: "Hill Valley",!
333
+ expected_line %!- zip: "90382"!
334
+ expected_line "- )>"
335
+ actual_line "+ address: nil"
336
+ plain_line " }"
337
+ end
338
+ )
318
339
 
319
- line do
320
- plain %|to match |
321
- expected %|{ name: "Marty McFly", address: #<a hash including (city: "Hill Valley", zip: "90382")> }|
322
- end
323
- },
324
- diff: proc {
325
- plain_line %! {!
326
- plain_line %! name: "Marty McFly",!
327
- expected_line %!- address: #<a hash including (!
328
- expected_line %!- city: "Hill Valley",!
329
- expected_line %!- zip: "90382"!
330
- expected_line %!- )>!
331
- actual_line %!+ address: nil!
332
- plain_line %! }!
333
- },
340
+ expect(program).to produce_output_when_run(expected_output).in_color(
341
+ color_enabled
334
342
  )
335
-
336
- expect(program).
337
- to produce_output_when_run(expected_output).
338
- in_color(color_enabled)
339
343
  end
340
344
  end
341
345
  end
@@ -348,37 +352,37 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
348
352
  as_both_colored_and_uncolored do |color_enabled|
349
353
  snippet = <<~TEST.strip
350
354
  expected = hash_including(city: "Hill Valley")
351
- actual = { city: "Burbank" }
355
+ actual = { city: "Burbank" }
352
356
  expect(actual).to match(expected)
353
357
  TEST
354
- program = make_plain_test_program(
355
- snippet,
356
- color_enabled: color_enabled,
357
- )
358
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
358
359
 
359
- expected_output = build_expected_output(
360
- color_enabled: color_enabled,
361
- snippet: %|expect(actual).to match(expected)|,
362
- expectation: proc {
363
- line do
364
- plain %|Expected |
365
- actual %|{ city: "Burbank" }|
366
- plain %| to match |
367
- expected %|#<a hash including (city: "Hill Valley")>|
368
- plain %|.|
369
- end
370
- },
371
- diff: proc {
372
- plain_line %| {|
373
- expected_line %|- city: "Hill Valley"|
374
- actual_line %|+ city: "Burbank"|
375
- plain_line %| }|
376
- },
377
- )
360
+ expected_output =
361
+ build_expected_output(
362
+ color_enabled: color_enabled,
363
+ snippet: "expect(actual).to match(expected)",
364
+ expectation:
365
+ proc do
366
+ line do
367
+ plain "Expected "
368
+ actual %|{ city: "Burbank" }|
369
+ plain " to match "
370
+ expected %|#<a hash including (city: "Hill Valley")>|
371
+ plain "."
372
+ end
373
+ end,
374
+ diff:
375
+ proc do
376
+ plain_line " {"
377
+ expected_line %|- city: "Hill Valley"|
378
+ actual_line %|+ city: "Burbank"|
379
+ plain_line " }"
380
+ end
381
+ )
378
382
 
379
- expect(program).
380
- to produce_output_when_run(expected_output).
381
- in_color(color_enabled)
383
+ expect(program).to produce_output_when_run(expected_output).in_color(
384
+ color_enabled
385
+ )
382
386
  end
383
387
  end
384
388
  end
@@ -389,38 +393,39 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
389
393
  as_both_colored_and_uncolored do |color_enabled|
390
394
  snippet = <<~TEST.strip
391
395
  expected = a_collection_including("a")
392
- actual = ["b"]
396
+ actual = ["b"]
393
397
  expect(actual).to match(expected)
394
398
  TEST
395
- program = make_plain_test_program(
396
- snippet,
397
- color_enabled: color_enabled,
398
- )
399
+ program =
400
+ make_plain_test_program(snippet, color_enabled: color_enabled)
401
+
402
+ expected_output =
403
+ build_expected_output(
404
+ color_enabled: color_enabled,
405
+ snippet: "expect(actual).to match(expected)",
406
+ expectation:
407
+ proc do
408
+ line do
409
+ plain "Expected "
410
+ actual %|["b"]|
411
+ plain " to match "
412
+ expected %|#<a collection including ("a")>|
413
+ plain "."
414
+ end
415
+ end,
416
+ diff:
417
+ proc do
418
+ plain_line " ["
419
+ plain_line %| "b"|
420
+ # expected_line %|- "a",| # FIXME
421
+ expected_line %|- "a"|
422
+ plain_line " ]"
423
+ end
424
+ )
399
425
 
400
- expected_output = build_expected_output(
401
- color_enabled: color_enabled,
402
- snippet: %|expect(actual).to match(expected)|,
403
- expectation: proc {
404
- line do
405
- plain %|Expected |
406
- actual %|["b"]|
407
- plain %| to match |
408
- expected %|#<a collection including ("a")>|
409
- plain %|.|
410
- end
411
- },
412
- diff: proc {
413
- plain_line %| [|
414
- plain_line %| "b"|
415
- # expected_line %|- "a",| # FIXME
416
- expected_line %|- "a"|
417
- plain_line %| ]|
418
- },
426
+ expect(program).to produce_output_when_run(expected_output).in_color(
427
+ color_enabled
419
428
  )
420
-
421
- expect(program).
422
- to produce_output_when_run(expected_output).
423
- in_color(color_enabled)
424
429
  end
425
430
  end
426
431
 
@@ -428,31 +433,31 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
428
433
  as_both_colored_and_uncolored do |color_enabled|
429
434
  snippet = <<~TEST.strip
430
435
  expected = a_collection_including("b")
431
- actual = ["b"]
436
+ actual = ["b"]
432
437
  expect(actual).not_to match(expected)
433
438
  TEST
434
- program = make_plain_test_program(
435
- snippet,
436
- color_enabled: color_enabled,
437
- )
439
+ program =
440
+ make_plain_test_program(snippet, color_enabled: color_enabled)
441
+
442
+ expected_output =
443
+ build_expected_output(
444
+ color_enabled: color_enabled,
445
+ snippet: "expect(actual).not_to match(expected)",
446
+ expectation:
447
+ proc do
448
+ line do
449
+ plain "Expected "
450
+ actual %|["b"]|
451
+ plain " not to match "
452
+ expected %|#<a collection including ("b")>|
453
+ plain "."
454
+ end
455
+ end
456
+ )
438
457
 
439
- expected_output = build_expected_output(
440
- color_enabled: color_enabled,
441
- snippet: %|expect(actual).not_to match(expected)|,
442
- expectation: proc {
443
- line do
444
- plain %|Expected |
445
- actual %|["b"]|
446
- plain %| not to match |
447
- expected %|#<a collection including ("b")>|
448
- plain %|.|
449
- end
450
- },
458
+ expect(program).to produce_output_when_run(expected_output).in_color(
459
+ color_enabled
451
460
  )
452
-
453
- expect(program).
454
- to produce_output_when_run(expected_output).
455
- in_color(color_enabled)
456
461
  end
457
462
  end
458
463
  end
@@ -462,44 +467,45 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
462
467
  as_both_colored_and_uncolored do |color_enabled|
463
468
  snippet = <<~TEST.strip
464
469
  expected = a_collection_including("milk", "bread")
465
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
470
+ actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
466
471
  expect(actual).to match(expected)
467
472
  TEST
468
- program = make_plain_test_program(
469
- snippet,
470
- color_enabled: color_enabled,
471
- )
472
-
473
- expected_output = build_expected_output(
474
- color_enabled: color_enabled,
475
- snippet: %|expect(actual).to match(expected)|,
476
- expectation: proc {
477
- line do
478
- plain %|Expected |
479
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
480
- end
473
+ program =
474
+ make_plain_test_program(snippet, color_enabled: color_enabled)
475
+
476
+ expected_output =
477
+ build_expected_output(
478
+ color_enabled: color_enabled,
479
+ snippet: "expect(actual).to match(expected)",
480
+ expectation:
481
+ proc do
482
+ line do
483
+ plain "Expected "
484
+ actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
485
+ end
486
+
487
+ line do
488
+ plain "to match "
489
+ expected %|#<a collection including ("milk", "bread")>|
490
+ end
491
+ end,
492
+ diff:
493
+ proc do
494
+ plain_line " ["
495
+ plain_line %| "milk",|
496
+ plain_line %| "toast",|
497
+ plain_line %| "eggs",|
498
+ plain_line %| "cheese",|
499
+ # plain_line %| "English muffins",| # FIXME
500
+ plain_line %| "English muffins"|
501
+ expected_line %|- "bread"|
502
+ plain_line " ]"
503
+ end
504
+ )
481
505
 
482
- line do
483
- plain %|to match |
484
- expected %|#<a collection including ("milk", "bread")>|
485
- end
486
- },
487
- diff: proc {
488
- plain_line %| [|
489
- plain_line %| "milk",|
490
- plain_line %| "toast",|
491
- plain_line %| "eggs",|
492
- plain_line %| "cheese",|
493
- # plain_line %| "English muffins",| # FIXME
494
- plain_line %| "English muffins"|
495
- expected_line %|- "bread"|
496
- plain_line %| ]|
497
- },
506
+ expect(program).to produce_output_when_run(expected_output).in_color(
507
+ color_enabled
498
508
  )
499
-
500
- expect(program).
501
- to produce_output_when_run(expected_output).
502
- in_color(color_enabled)
503
509
  end
504
510
  end
505
511
 
@@ -507,41 +513,41 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
507
513
  as_both_colored_and_uncolored do |color_enabled|
508
514
  snippet = <<~TEST.strip
509
515
  expected = a_collection_including("milk", "toast")
510
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
516
+ actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
511
517
  expect(actual).not_to match(expected)
512
518
  TEST
513
- program = make_plain_test_program(
514
- snippet,
515
- color_enabled: color_enabled,
516
- )
517
-
518
- expected_output = build_expected_output(
519
- color_enabled: color_enabled,
520
- snippet: %|expect(actual).not_to match(expected)|,
521
- newline_before_expectation: true,
522
- expectation: proc {
523
- line do
524
- plain %| Expected |
525
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
526
- end
519
+ program =
520
+ make_plain_test_program(snippet, color_enabled: color_enabled)
521
+
522
+ expected_output =
523
+ build_expected_output(
524
+ color_enabled: color_enabled,
525
+ snippet: "expect(actual).not_to match(expected)",
526
+ newline_before_expectation: true,
527
+ expectation:
528
+ proc do
529
+ line do
530
+ plain " Expected "
531
+ actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
532
+ end
533
+
534
+ line do
535
+ plain "not to match "
536
+ expected %|#<a collection including ("milk", "toast")>|
537
+ end
538
+ end
539
+ )
527
540
 
528
- line do
529
- plain %|not to match |
530
- expected %|#<a collection including ("milk", "toast")>|
531
- end
532
- },
541
+ expect(program).to produce_output_when_run(expected_output).in_color(
542
+ color_enabled
533
543
  )
534
-
535
- expect(program).
536
- to produce_output_when_run(expected_output).
537
- in_color(color_enabled)
538
544
  end
539
545
  end
540
546
  end
541
547
  end
542
548
 
543
549
  context "when the expected value includes a collection-including-<something>" do
544
- context "and the corresponding actual value is an array" do
550
+ context "and the corresponding actual value is an array" do
545
551
  it "produces the correct failure message when used in the positive" do
546
552
  as_both_colored_and_uncolored do |color_enabled|
547
553
  snippet = <<~TEST.strip
@@ -549,48 +555,49 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
549
555
  name: "shopping list",
550
556
  contents: a_collection_including("milk", "bread")
551
557
  }
552
- actual = {
558
+ actual = {
553
559
  name: "shopping list",
554
560
  contents: ["milk", "toast", "eggs"]
555
561
  }
556
562
  expect(actual).to match(expected)
557
563
  TEST
558
- program = make_plain_test_program(
559
- snippet,
560
- color_enabled: color_enabled,
561
- )
562
-
563
- expected_output = build_expected_output(
564
- color_enabled: color_enabled,
565
- snippet: %|expect(actual).to match(expected)|,
566
- expectation: proc {
567
- line do
568
- plain %|Expected |
569
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
570
- end
564
+ program =
565
+ make_plain_test_program(snippet, color_enabled: color_enabled)
566
+
567
+ expected_output =
568
+ build_expected_output(
569
+ color_enabled: color_enabled,
570
+ snippet: "expect(actual).to match(expected)",
571
+ expectation:
572
+ proc do
573
+ line do
574
+ plain "Expected "
575
+ actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
576
+ end
577
+
578
+ line do
579
+ plain "to match "
580
+ expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
581
+ end
582
+ end,
583
+ diff:
584
+ proc do
585
+ plain_line " {"
586
+ plain_line %| name: "shopping list",|
587
+ plain_line " contents: ["
588
+ plain_line %| "milk",|
589
+ plain_line %| "toast",|
590
+ # plain_line %| "eggs",| # FIXME
591
+ plain_line %| "eggs"|
592
+ expected_line %|- "bread"|
593
+ plain_line " ]"
594
+ plain_line " }"
595
+ end
596
+ )
571
597
 
572
- line do
573
- plain %|to match |
574
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
575
- end
576
- },
577
- diff: proc {
578
- plain_line %| {|
579
- plain_line %| name: "shopping list",|
580
- plain_line %| contents: [|
581
- plain_line %| "milk",|
582
- plain_line %| "toast",|
583
- # plain_line %| "eggs",| # FIXME
584
- plain_line %| "eggs"|
585
- expected_line %|- "bread"|
586
- plain_line %| ]|
587
- plain_line %| }|
588
- },
598
+ expect(program).to produce_output_when_run(expected_output).in_color(
599
+ color_enabled
589
600
  )
590
-
591
- expect(program).
592
- to produce_output_when_run(expected_output).
593
- in_color(color_enabled)
594
601
  end
595
602
  end
596
603
 
@@ -601,42 +608,42 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
601
608
  name: "shopping list",
602
609
  contents: a_collection_including("milk", "toast")
603
610
  }
604
- actual = {
611
+ actual = {
605
612
  name: "shopping list",
606
613
  contents: ["milk", "toast", "eggs"]
607
614
  }
608
615
  expect(actual).not_to match(expected)
609
616
  TEST
610
- program = make_plain_test_program(
611
- snippet,
612
- color_enabled: color_enabled,
613
- )
614
-
615
- expected_output = build_expected_output(
616
- color_enabled: color_enabled,
617
- snippet: %|expect(actual).not_to match(expected)|,
618
- newline_before_expectation: true,
619
- expectation: proc {
620
- line do
621
- plain %| Expected |
622
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
623
- end
617
+ program =
618
+ make_plain_test_program(snippet, color_enabled: color_enabled)
619
+
620
+ expected_output =
621
+ build_expected_output(
622
+ color_enabled: color_enabled,
623
+ snippet: "expect(actual).not_to match(expected)",
624
+ newline_before_expectation: true,
625
+ expectation:
626
+ proc do
627
+ line do
628
+ plain " Expected "
629
+ actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
630
+ end
631
+
632
+ line do
633
+ plain "not to match "
634
+ expected %|{ name: "shopping list", contents: #<a collection including ("milk", "toast")> }|
635
+ end
636
+ end
637
+ )
624
638
 
625
- line do
626
- plain %|not to match |
627
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "toast")> }|
628
- end
629
- },
639
+ expect(program).to produce_output_when_run(expected_output).in_color(
640
+ color_enabled
630
641
  )
631
-
632
- expect(program).
633
- to produce_output_when_run(expected_output).
634
- in_color(color_enabled)
635
642
  end
636
643
  end
637
644
  end
638
645
 
639
- context "when the corresponding actual value is not an array" do
646
+ context "when the corresponding actual value is not an array" do
640
647
  it "produces the correct failure message" do
641
648
  as_both_colored_and_uncolored do |color_enabled|
642
649
  snippet = <<~TEST.strip
@@ -644,46 +651,47 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
644
651
  name: "shopping list",
645
652
  contents: a_collection_including("milk", "bread")
646
653
  }
647
- actual = {
654
+ actual = {
648
655
  name: "shopping list",
649
656
  contents: nil
650
657
  }
651
658
  expect(actual).to match(expected)
652
659
  TEST
653
- program = make_plain_test_program(
654
- snippet,
655
- color_enabled: color_enabled,
656
- )
657
-
658
- expected_output = build_expected_output(
659
- color_enabled: color_enabled,
660
- snippet: %|expect(actual).to match(expected)|,
661
- expectation: proc {
662
- line do
663
- plain %|Expected |
664
- actual %|{ name: "shopping list", contents: nil }|
665
- end
660
+ program =
661
+ make_plain_test_program(snippet, color_enabled: color_enabled)
662
+
663
+ expected_output =
664
+ build_expected_output(
665
+ color_enabled: color_enabled,
666
+ snippet: "expect(actual).to match(expected)",
667
+ expectation:
668
+ proc do
669
+ line do
670
+ plain "Expected "
671
+ actual %|{ name: "shopping list", contents: nil }|
672
+ end
673
+
674
+ line do
675
+ plain "to match "
676
+ expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
677
+ end
678
+ end,
679
+ diff:
680
+ proc do
681
+ plain_line " {"
682
+ plain_line %! name: "shopping list",!
683
+ expected_line "- contents: #<a collection including ("
684
+ expected_line %!- "milk",!
685
+ expected_line %!- "bread"!
686
+ expected_line "- )>"
687
+ actual_line "+ contents: nil"
688
+ plain_line " }"
689
+ end
690
+ )
666
691
 
667
- line do
668
- plain %|to match |
669
- expected %|{ name: "shopping list", contents: #<a collection including ("milk", "bread")> }|
670
- end
671
- },
672
- diff: proc {
673
- plain_line %! {!
674
- plain_line %! name: "shopping list",!
675
- expected_line %!- contents: #<a collection including (!
676
- expected_line %!- "milk",!
677
- expected_line %!- "bread"!
678
- expected_line %!- )>!
679
- actual_line %!+ contents: nil!
680
- plain_line %! }!
681
- },
692
+ expect(program).to produce_output_when_run(expected_output).in_color(
693
+ color_enabled
682
694
  )
683
-
684
- expect(program).
685
- to produce_output_when_run(expected_output).
686
- in_color(color_enabled)
687
695
  end
688
696
  end
689
697
  end
@@ -694,38 +702,38 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
694
702
  as_both_colored_and_uncolored do |color_enabled|
695
703
  snippet = <<~TEST.strip
696
704
  expected = array_including("a")
697
- actual = ["b"]
705
+ actual = ["b"]
698
706
  expect(actual).to match(expected)
699
707
  TEST
700
- program = make_plain_test_program(
701
- snippet,
702
- color_enabled: color_enabled,
703
- )
708
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
704
709
 
705
- expected_output = build_expected_output(
706
- color_enabled: color_enabled,
707
- snippet: %|expect(actual).to match(expected)|,
708
- expectation: proc {
709
- line do
710
- plain %|Expected |
711
- actual %|["b"]|
712
- plain %| to match |
713
- expected %|#<a collection including ("a")>|
714
- plain %|.|
715
- end
716
- },
717
- diff: proc {
718
- plain_line %| [|
719
- plain_line %| "b"|
720
- # expected_line %|- "a",| # FIXME
721
- expected_line %|- "a"|
722
- plain_line %| ]|
723
- },
724
- )
710
+ expected_output =
711
+ build_expected_output(
712
+ color_enabled: color_enabled,
713
+ snippet: "expect(actual).to match(expected)",
714
+ expectation:
715
+ proc do
716
+ line do
717
+ plain "Expected "
718
+ actual %|["b"]|
719
+ plain " to match "
720
+ expected %|#<a collection including ("a")>|
721
+ plain "."
722
+ end
723
+ end,
724
+ diff:
725
+ proc do
726
+ plain_line " ["
727
+ plain_line %| "b"|
728
+ # expected_line %|- "a",| # FIXME
729
+ expected_line %|- "a"|
730
+ plain_line " ]"
731
+ end
732
+ )
725
733
 
726
- expect(program).
727
- to produce_output_when_run(expected_output).
728
- in_color(color_enabled)
734
+ expect(program).to produce_output_when_run(expected_output).in_color(
735
+ color_enabled
736
+ )
729
737
  end
730
738
  end
731
739
  end
@@ -736,38 +744,39 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
736
744
  as_both_colored_and_uncolored do |color_enabled|
737
745
  snippet = <<~TEST.strip
738
746
  expected = an_object_having_attributes(name: "b")
739
- actual = A.new("a")
747
+ actual = A.new("a")
740
748
  expect(actual).to match(expected)
741
749
  TEST
742
- program = make_plain_test_program(
743
- snippet,
744
- color_enabled: color_enabled,
745
- )
750
+ program =
751
+ make_plain_test_program(snippet, color_enabled: color_enabled)
752
+
753
+ expected_output =
754
+ build_expected_output(
755
+ color_enabled: color_enabled,
756
+ snippet: "expect(actual).to match(expected)",
757
+ expectation:
758
+ proc do
759
+ line do
760
+ plain "Expected "
761
+ actual %|#<A name: "a">|
762
+ plain " to match "
763
+ expected %|#<an object having attributes (name: "b")>|
764
+ plain "."
765
+ end
766
+ end,
767
+ diff:
768
+ proc do
769
+ plain_line " #<A {"
770
+ # expected_line %|- name: "b",| # FIXME
771
+ expected_line %|- name: "b"|
772
+ actual_line %|+ name: "a"|
773
+ plain_line " }>"
774
+ end
775
+ )
746
776
 
747
- expected_output = build_expected_output(
748
- color_enabled: color_enabled,
749
- snippet: %|expect(actual).to match(expected)|,
750
- expectation: proc {
751
- line do
752
- plain %|Expected |
753
- actual %|#<A name: "a">|
754
- plain %| to match |
755
- expected %|#<an object having attributes (name: "b")>|
756
- plain %|.|
757
- end
758
- },
759
- diff: proc {
760
- plain_line %| #<A {|
761
- # expected_line %|- name: "b",| # FIXME
762
- expected_line %|- name: "b"|
763
- actual_line %|+ name: "a"|
764
- plain_line %| }>|
765
- },
777
+ expect(program).to produce_output_when_run(expected_output).in_color(
778
+ color_enabled
766
779
  )
767
-
768
- expect(program).
769
- to produce_output_when_run(expected_output).
770
- in_color(color_enabled)
771
780
  end
772
781
  end
773
782
 
@@ -775,31 +784,31 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
775
784
  as_both_colored_and_uncolored do |color_enabled|
776
785
  snippet = <<~TEST.strip
777
786
  expected = an_object_having_attributes(name: "b")
778
- actual = A.new("b")
787
+ actual = A.new("b")
779
788
  expect(actual).not_to match(expected)
780
789
  TEST
781
- program = make_plain_test_program(
782
- snippet,
783
- color_enabled: color_enabled,
784
- )
790
+ program =
791
+ make_plain_test_program(snippet, color_enabled: color_enabled)
792
+
793
+ expected_output =
794
+ build_expected_output(
795
+ color_enabled: color_enabled,
796
+ snippet: "expect(actual).not_to match(expected)",
797
+ expectation:
798
+ proc do
799
+ line do
800
+ plain "Expected "
801
+ actual %|#<A name: "b">|
802
+ plain " not to match "
803
+ expected %|#<an object having attributes (name: "b")>|
804
+ plain "."
805
+ end
806
+ end
807
+ )
785
808
 
786
- expected_output = build_expected_output(
787
- color_enabled: color_enabled,
788
- snippet: %|expect(actual).not_to match(expected)|,
789
- expectation: proc {
790
- line do
791
- plain %|Expected |
792
- actual %|#<A name: "b">|
793
- plain %| not to match |
794
- expected %|#<an object having attributes (name: "b")>|
795
- plain %|.|
796
- end
797
- },
809
+ expect(program).to produce_output_when_run(expected_output).in_color(
810
+ color_enabled
798
811
  )
799
-
800
- expect(program).
801
- to produce_output_when_run(expected_output).
802
- in_color(color_enabled)
803
812
  end
804
813
  end
805
814
  end
@@ -815,7 +824,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
815
824
  state: "CA",
816
825
  something_else: "blah"
817
826
  )
818
- actual = SuperDiff::Test::ShippingAddress.new(
827
+ actual = SuperDiff::Test::ShippingAddress.new(
819
828
  line_1: "456 Ponderosa Ct.",
820
829
  line_2: nil,
821
830
  city: "Hill Valley",
@@ -824,46 +833,47 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
824
833
  )
825
834
  expect(actual).to match(expected)
826
835
  TEST
827
- program = make_plain_test_program(
828
- snippet,
829
- color_enabled: color_enabled,
830
- )
831
-
832
- expected_output = build_expected_output(
833
- color_enabled: color_enabled,
834
- snippet: %|expect(actual).to match(expected)|,
835
- expectation: proc {
836
- line do
837
- plain %|Expected |
838
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
839
- end
836
+ program =
837
+ make_plain_test_program(snippet, color_enabled: color_enabled)
838
+
839
+ expected_output =
840
+ build_expected_output(
841
+ color_enabled: color_enabled,
842
+ snippet: "expect(actual).to match(expected)",
843
+ expectation:
844
+ proc do
845
+ line do
846
+ plain "Expected "
847
+ actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
848
+ end
849
+
850
+ line do
851
+ plain "to match "
852
+ expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234", state: "CA", something_else: "blah")>|
853
+ end
854
+ end,
855
+ diff:
856
+ proc do
857
+ plain_line " #<SuperDiff::Test::ShippingAddress {"
858
+ expected_line %|- line_1: "123 Main St.",|
859
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
860
+ plain_line " line_2: nil,"
861
+ expected_line %|- city: "Oakland",|
862
+ actual_line %|+ city: "Hill Valley",|
863
+ plain_line %| state: "CA",|
864
+ # expected_line %|- zip: "91234",| # FIXME
865
+ # actual_line %|+ zip: "90382",| # FIXME
866
+ expected_line %|- zip: "91234"|
867
+ actual_line %|+ zip: "90382"|
868
+ # expected_line %|- something_else: "blah"| # TODO
869
+ expected_line %|- something_else: "blah",|
870
+ plain_line " }>"
871
+ end
872
+ )
840
873
 
841
- line do
842
- plain %|to match |
843
- expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234", state: "CA", something_else: "blah")>|
844
- end
845
- },
846
- diff: proc {
847
- plain_line %| #<SuperDiff::Test::ShippingAddress {|
848
- expected_line %|- line_1: "123 Main St.",|
849
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
850
- plain_line %| line_2: nil,|
851
- expected_line %|- city: "Oakland",|
852
- actual_line %|+ city: "Hill Valley",|
853
- plain_line %| state: "CA",|
854
- # expected_line %|- zip: "91234",| # FIXME
855
- # actual_line %|+ zip: "90382",| # FIXME
856
- expected_line %|- zip: "91234"|
857
- actual_line %|+ zip: "90382"|
858
- # expected_line %|- something_else: "blah"| # TODO
859
- expected_line %|- something_else: "blah",|
860
- plain_line %| }>|
861
- },
874
+ expect(program).to produce_output_when_run(expected_output).in_color(
875
+ color_enabled
862
876
  )
863
-
864
- expect(program).
865
- to produce_output_when_run(expected_output).
866
- in_color(color_enabled)
867
877
  end
868
878
  end
869
879
 
@@ -875,7 +885,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
875
885
  city: "Oakland",
876
886
  zip: "91234"
877
887
  )
878
- actual = SuperDiff::Test::ShippingAddress.new(
888
+ actual = SuperDiff::Test::ShippingAddress.new(
879
889
  line_1: "123 Main St.",
880
890
  line_2: nil,
881
891
  city: "Oakland",
@@ -884,31 +894,31 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
884
894
  )
885
895
  expect(actual).not_to match(expected)
886
896
  TEST
887
- program = make_plain_test_program(
888
- snippet,
889
- color_enabled: color_enabled,
890
- )
891
-
892
- expected_output = build_expected_output(
893
- color_enabled: color_enabled,
894
- snippet: %|expect(actual).not_to match(expected)|,
895
- newline_before_expectation: true,
896
- expectation: proc {
897
- line do
898
- plain %| Expected |
899
- actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
900
- end
897
+ program =
898
+ make_plain_test_program(snippet, color_enabled: color_enabled)
899
+
900
+ expected_output =
901
+ build_expected_output(
902
+ color_enabled: color_enabled,
903
+ snippet: "expect(actual).not_to match(expected)",
904
+ newline_before_expectation: true,
905
+ expectation:
906
+ proc do
907
+ line do
908
+ plain " Expected "
909
+ actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
910
+ end
911
+
912
+ line do
913
+ plain "not to match "
914
+ expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234")>|
915
+ end
916
+ end
917
+ )
901
918
 
902
- line do
903
- plain %|not to match |
904
- expected %|#<an object having attributes (line_1: "123 Main St.", city: "Oakland", zip: "91234")>|
905
- end
906
- },
919
+ expect(program).to produce_output_when_run(expected_output).in_color(
920
+ color_enabled
907
921
  )
908
-
909
- expect(program).
910
- to produce_output_when_run(expected_output).
911
- in_color(color_enabled)
912
922
  end
913
923
  end
914
924
  end
@@ -928,7 +938,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
928
938
  something_else: "blah"
929
939
  )
930
940
  }
931
- actual = {
941
+ actual = {
932
942
  name: "Marty McFly",
933
943
  shipping_address: SuperDiff::Test::ShippingAddress.new(
934
944
  line_1: "456 Ponderosa Ct.",
@@ -940,48 +950,48 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
940
950
  }
941
951
  expect(actual).to match(expected)
942
952
  TEST
943
- program = make_plain_test_program(
944
- snippet,
945
- color_enabled: color_enabled,
946
- )
953
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
947
954
 
948
- expected_output = build_expected_output(
949
- color_enabled: color_enabled,
950
- snippet: %|expect(actual).to match(expected)|,
951
- expectation: proc {
952
- line do
953
- plain %|Expected |
954
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382"> }|
955
- end
956
-
957
- line do
958
- plain %|to match |
959
- expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234", something_else: "blah")> }|
960
- end
961
- },
962
- diff: proc {
963
- plain_line %| {|
964
- plain_line %| name: "Marty McFly",|
965
- plain_line %| shipping_address: #<SuperDiff::Test::ShippingAddress {|
966
- expected_line %|- line_1: "123 Main St.",|
967
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
968
- plain_line %| line_2: nil,|
969
- expected_line %|- city: "Oakland",|
970
- actual_line %|+ city: "Hill Valley",|
971
- plain_line %| state: "CA",|
972
- # expected_line %|- zip: "91234",| # FIXME
973
- expected_line %|- zip: "91234"|
974
- actual_line %|+ zip: "90382"|
975
- # expected_line %|- something_else: "blah"| # TODO
976
- expected_line %|- something_else: "blah",|
977
- plain_line %| }>|
978
- plain_line %| }|
979
- },
980
- )
955
+ expected_output =
956
+ build_expected_output(
957
+ color_enabled: color_enabled,
958
+ snippet: "expect(actual).to match(expected)",
959
+ expectation:
960
+ proc do
961
+ line do
962
+ plain "Expected "
963
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382"> }|
964
+ end
965
+
966
+ line do
967
+ plain "to match "
968
+ expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234", something_else: "blah")> }|
969
+ end
970
+ end,
971
+ diff:
972
+ proc do
973
+ plain_line " {"
974
+ plain_line %| name: "Marty McFly",|
975
+ plain_line " shipping_address: #<SuperDiff::Test::ShippingAddress {"
976
+ expected_line %|- line_1: "123 Main St.",|
977
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
978
+ plain_line " line_2: nil,"
979
+ expected_line %|- city: "Oakland",|
980
+ actual_line %|+ city: "Hill Valley",|
981
+ plain_line %| state: "CA",|
982
+ # expected_line %|- zip: "91234",| # FIXME
983
+ expected_line %|- zip: "91234"|
984
+ actual_line %|+ zip: "90382"|
985
+ # expected_line %|- something_else: "blah"| # TODO
986
+ expected_line %|- something_else: "blah",|
987
+ plain_line " }>"
988
+ plain_line " }"
989
+ end
990
+ )
981
991
 
982
- expect(program).
983
- to produce_output_when_run(expected_output).
984
- in_color(color_enabled)
992
+ expect(program).to produce_output_when_run(expected_output).in_color(
993
+ color_enabled
994
+ )
985
995
  end
986
996
  end
987
997
 
@@ -997,7 +1007,7 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
997
1007
  zip: "91234"
998
1008
  )
999
1009
  }
1000
- actual = {
1010
+ actual = {
1001
1011
  name: "Marty McFly",
1002
1012
  shipping_address: SuperDiff::Test::ShippingAddress.new(
1003
1013
  line_1: "123 Main St.",
@@ -1009,31 +1019,30 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1009
1019
  }
1010
1020
  expect(actual).not_to match(expected)
1011
1021
  TEST
1012
- program = make_plain_test_program(
1013
- snippet,
1014
- color_enabled: color_enabled,
1015
- )
1022
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
1016
1023
 
1017
- expected_output = build_expected_output(
1018
- color_enabled: color_enabled,
1019
- snippet: %|expect(actual).not_to match(expected)|,
1020
- newline_before_expectation: true,
1021
- expectation: proc {
1022
- line do
1023
- plain %| Expected |
1024
- actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234"> }|
1025
- end
1026
-
1027
- line do
1028
- plain %|not to match |
1029
- expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")> }|
1030
- end
1031
- },
1032
- )
1024
+ expected_output =
1025
+ build_expected_output(
1026
+ color_enabled: color_enabled,
1027
+ snippet: "expect(actual).not_to match(expected)",
1028
+ newline_before_expectation: true,
1029
+ expectation:
1030
+ proc do
1031
+ line do
1032
+ plain " Expected "
1033
+ actual %|{ name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234"> }|
1034
+ end
1035
+
1036
+ line do
1037
+ plain "not to match "
1038
+ expected %|{ name: "Marty McFly", shipping_address: #<an object having attributes (line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")> }|
1039
+ end
1040
+ end
1041
+ )
1033
1042
 
1034
- expect(program).
1035
- to produce_output_when_run(expected_output).
1036
- in_color(color_enabled)
1043
+ expect(program).to produce_output_when_run(expected_output).in_color(
1044
+ color_enabled
1045
+ )
1037
1046
  end
1038
1047
  end
1039
1048
  end
@@ -1044,38 +1053,39 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1044
1053
  as_both_colored_and_uncolored do |color_enabled|
1045
1054
  snippet = <<~TEST.strip
1046
1055
  expected = a_collection_containing_exactly("a")
1047
- actual = ["b"]
1056
+ actual = ["b"]
1048
1057
  expect(actual).to match(expected)
1049
1058
  TEST
1050
- program = make_plain_test_program(
1051
- snippet,
1052
- color_enabled: color_enabled,
1053
- )
1059
+ program =
1060
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1061
+
1062
+ expected_output =
1063
+ build_expected_output(
1064
+ color_enabled: color_enabled,
1065
+ snippet: "expect(actual).to match(expected)",
1066
+ expectation:
1067
+ proc do
1068
+ line do
1069
+ plain "Expected "
1070
+ actual %|["b"]|
1071
+ plain " to match "
1072
+ expected %|#<a collection containing exactly ("a")>|
1073
+ plain "."
1074
+ end
1075
+ end,
1076
+ diff:
1077
+ proc do
1078
+ plain_line " ["
1079
+ actual_line %|+ "b",|
1080
+ # expected_line %|- "a"| # TODO
1081
+ expected_line %|- "a",|
1082
+ plain_line " ]"
1083
+ end
1084
+ )
1054
1085
 
1055
- expected_output = build_expected_output(
1056
- color_enabled: color_enabled,
1057
- snippet: %|expect(actual).to match(expected)|,
1058
- expectation: proc {
1059
- line do
1060
- plain %|Expected |
1061
- actual %|["b"]|
1062
- plain %| to match |
1063
- expected %|#<a collection containing exactly ("a")>|
1064
- plain %|.|
1065
- end
1066
- },
1067
- diff: proc {
1068
- plain_line %| [|
1069
- actual_line %|+ "b",|
1070
- # expected_line %|- "a"| # TODO
1071
- expected_line %|- "a",|
1072
- plain_line %| ]|
1073
- },
1086
+ expect(program).to produce_output_when_run(expected_output).in_color(
1087
+ color_enabled
1074
1088
  )
1075
-
1076
- expect(program).
1077
- to produce_output_when_run(expected_output).
1078
- in_color(color_enabled)
1079
1089
  end
1080
1090
  end
1081
1091
 
@@ -1083,31 +1093,31 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1083
1093
  as_both_colored_and_uncolored do |color_enabled|
1084
1094
  snippet = <<~TEST.strip
1085
1095
  expected = a_collection_containing_exactly("b")
1086
- actual = ["b"]
1096
+ actual = ["b"]
1087
1097
  expect(actual).not_to match(expected)
1088
1098
  TEST
1089
- program = make_plain_test_program(
1090
- snippet,
1091
- color_enabled: color_enabled,
1092
- )
1099
+ program =
1100
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1101
+
1102
+ expected_output =
1103
+ build_expected_output(
1104
+ color_enabled: color_enabled,
1105
+ snippet: "expect(actual).not_to match(expected)",
1106
+ expectation:
1107
+ proc do
1108
+ line do
1109
+ plain "Expected "
1110
+ actual %|["b"]|
1111
+ plain " not to match "
1112
+ expected %|#<a collection containing exactly ("b")>|
1113
+ plain "."
1114
+ end
1115
+ end
1116
+ )
1093
1117
 
1094
- expected_output = build_expected_output(
1095
- color_enabled: color_enabled,
1096
- snippet: %|expect(actual).not_to match(expected)|,
1097
- expectation: proc {
1098
- line do
1099
- plain %|Expected |
1100
- actual %|["b"]|
1101
- plain %| not to match |
1102
- expected %|#<a collection containing exactly ("b")>|
1103
- plain %|.|
1104
- end
1105
- },
1118
+ expect(program).to produce_output_when_run(expected_output).in_color(
1119
+ color_enabled
1106
1120
  )
1107
-
1108
- expect(program).
1109
- to produce_output_when_run(expected_output).
1110
- in_color(color_enabled)
1111
1121
  end
1112
1122
  end
1113
1123
  end
@@ -1117,44 +1127,45 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1117
1127
  as_both_colored_and_uncolored do |color_enabled|
1118
1128
  snippet = <<~TEST.strip
1119
1129
  expected = a_collection_containing_exactly("milk", "bread")
1120
- actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
1130
+ actual = ["milk", "toast", "eggs", "cheese", "English muffins"]
1121
1131
  expect(actual).to match(expected)
1122
1132
  TEST
1123
- program = make_plain_test_program(
1124
- snippet,
1125
- color_enabled: color_enabled,
1126
- )
1127
-
1128
- expected_output = build_expected_output(
1129
- color_enabled: color_enabled,
1130
- snippet: %|expect(actual).to match(expected)|,
1131
- expectation: proc {
1132
- line do
1133
- plain %|Expected |
1134
- actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
1135
- end
1133
+ program =
1134
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1135
+
1136
+ expected_output =
1137
+ build_expected_output(
1138
+ color_enabled: color_enabled,
1139
+ snippet: "expect(actual).to match(expected)",
1140
+ expectation:
1141
+ proc do
1142
+ line do
1143
+ plain "Expected "
1144
+ actual %|["milk", "toast", "eggs", "cheese", "English muffins"]|
1145
+ end
1146
+
1147
+ line do
1148
+ plain "to match "
1149
+ expected %|#<a collection containing exactly ("milk", "bread")>|
1150
+ end
1151
+ end,
1152
+ diff:
1153
+ proc do
1154
+ plain_line " ["
1155
+ plain_line %| "milk",|
1156
+ actual_line %|+ "toast",|
1157
+ actual_line %|+ "eggs",|
1158
+ actual_line %|+ "cheese",|
1159
+ actual_line %|+ "English muffins",|
1160
+ # expected_line %|- "bread"| # TODO
1161
+ expected_line %|- "bread",|
1162
+ plain_line " ]"
1163
+ end
1164
+ )
1136
1165
 
1137
- line do
1138
- plain %|to match |
1139
- expected %|#<a collection containing exactly ("milk", "bread")>|
1140
- end
1141
- },
1142
- diff: proc {
1143
- plain_line %| [|
1144
- plain_line %| "milk",|
1145
- actual_line %|+ "toast",|
1146
- actual_line %|+ "eggs",|
1147
- actual_line %|+ "cheese",|
1148
- actual_line %|+ "English muffins",|
1149
- # expected_line %|- "bread"| # TODO
1150
- expected_line %|- "bread",|
1151
- plain_line %| ]|
1152
- },
1166
+ expect(program).to produce_output_when_run(expected_output).in_color(
1167
+ color_enabled
1153
1168
  )
1154
-
1155
- expect(program).
1156
- to produce_output_when_run(expected_output).
1157
- in_color(color_enabled)
1158
1169
  end
1159
1170
  end
1160
1171
 
@@ -1162,41 +1173,41 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1162
1173
  as_both_colored_and_uncolored do |color_enabled|
1163
1174
  snippet = <<~TEST.strip
1164
1175
  expected = a_collection_containing_exactly("milk", "eggs", "toast")
1165
- actual = ["milk", "toast", "eggs"]
1176
+ actual = ["milk", "toast", "eggs"]
1166
1177
  expect(actual).not_to match(expected)
1167
1178
  TEST
1168
- program = make_plain_test_program(
1169
- snippet,
1170
- color_enabled: color_enabled,
1171
- )
1172
-
1173
- expected_output = build_expected_output(
1174
- color_enabled: color_enabled,
1175
- snippet: %|expect(actual).not_to match(expected)|,
1176
- newline_before_expectation: true,
1177
- expectation: proc {
1178
- line do
1179
- plain %| Expected |
1180
- actual %|["milk", "toast", "eggs"]|
1181
- end
1179
+ program =
1180
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1181
+
1182
+ expected_output =
1183
+ build_expected_output(
1184
+ color_enabled: color_enabled,
1185
+ snippet: "expect(actual).not_to match(expected)",
1186
+ newline_before_expectation: true,
1187
+ expectation:
1188
+ proc do
1189
+ line do
1190
+ plain " Expected "
1191
+ actual %|["milk", "toast", "eggs"]|
1192
+ end
1193
+
1194
+ line do
1195
+ plain "not to match "
1196
+ expected %|#<a collection containing exactly ("milk", "eggs", "toast")>|
1197
+ end
1198
+ end
1199
+ )
1182
1200
 
1183
- line do
1184
- plain %|not to match |
1185
- expected %|#<a collection containing exactly ("milk", "eggs", "toast")>|
1186
- end
1187
- },
1201
+ expect(program).to produce_output_when_run(expected_output).in_color(
1202
+ color_enabled
1188
1203
  )
1189
-
1190
- expect(program).
1191
- to produce_output_when_run(expected_output).
1192
- in_color(color_enabled)
1193
1204
  end
1194
1205
  end
1195
1206
  end
1196
1207
  end
1197
1208
 
1198
1209
  context "when the expected value includes a collection-containing-exactly-<something>" do
1199
- context "and the corresponding actual value is an array" do
1210
+ context "and the corresponding actual value is an array" do
1200
1211
  it "produces the correct failure message when used in the positive" do
1201
1212
  as_both_colored_and_uncolored do |color_enabled|
1202
1213
  snippet = <<~TEST.strip
@@ -1204,48 +1215,49 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1204
1215
  name: "shopping list",
1205
1216
  contents: a_collection_containing_exactly("milk", "bread")
1206
1217
  }
1207
- actual = {
1218
+ actual = {
1208
1219
  name: "shopping list",
1209
1220
  contents: ["milk", "toast", "eggs"]
1210
1221
  }
1211
1222
  expect(actual).to match(expected)
1212
1223
  TEST
1213
- program = make_plain_test_program(
1214
- snippet,
1215
- color_enabled: color_enabled,
1216
- )
1217
-
1218
- expected_output = build_expected_output(
1219
- color_enabled: color_enabled,
1220
- snippet: %|expect(actual).to match(expected)|,
1221
- expectation: proc {
1222
- line do
1223
- plain %|Expected |
1224
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1225
- end
1224
+ program =
1225
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1226
+
1227
+ expected_output =
1228
+ build_expected_output(
1229
+ color_enabled: color_enabled,
1230
+ snippet: "expect(actual).to match(expected)",
1231
+ expectation:
1232
+ proc do
1233
+ line do
1234
+ plain "Expected "
1235
+ actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1236
+ end
1237
+
1238
+ line do
1239
+ plain "to match "
1240
+ expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1241
+ end
1242
+ end,
1243
+ diff:
1244
+ proc do
1245
+ plain_line " {"
1246
+ plain_line %| name: "shopping list",|
1247
+ plain_line " contents: ["
1248
+ plain_line %| "milk",|
1249
+ actual_line %|+ "toast",|
1250
+ actual_line %|+ "eggs",|
1251
+ # expected_line %|- "bread"| # TODO
1252
+ expected_line %|- "bread",|
1253
+ plain_line " ]"
1254
+ plain_line " }"
1255
+ end
1256
+ )
1226
1257
 
1227
- line do
1228
- plain %|to match |
1229
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1230
- end
1231
- },
1232
- diff: proc {
1233
- plain_line %| {|
1234
- plain_line %| name: "shopping list",|
1235
- plain_line %| contents: [|
1236
- plain_line %| "milk",|
1237
- actual_line %|+ "toast",|
1238
- actual_line %|+ "eggs",|
1239
- # expected_line %|- "bread"| # TODO
1240
- expected_line %|- "bread",|
1241
- plain_line %| ]|
1242
- plain_line %| }|
1243
- },
1258
+ expect(program).to produce_output_when_run(expected_output).in_color(
1259
+ color_enabled
1244
1260
  )
1245
-
1246
- expect(program).
1247
- to produce_output_when_run(expected_output).
1248
- in_color(color_enabled)
1249
1261
  end
1250
1262
  end
1251
1263
 
@@ -1256,42 +1268,42 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1256
1268
  name: "shopping list",
1257
1269
  contents: a_collection_containing_exactly("milk", "eggs", "toast")
1258
1270
  }
1259
- actual = {
1271
+ actual = {
1260
1272
  name: "shopping list",
1261
1273
  contents: ["milk", "toast", "eggs"]
1262
1274
  }
1263
1275
  expect(actual).not_to match(expected)
1264
1276
  TEST
1265
- program = make_plain_test_program(
1266
- snippet,
1267
- color_enabled: color_enabled,
1268
- )
1269
-
1270
- expected_output = build_expected_output(
1271
- color_enabled: color_enabled,
1272
- snippet: %|expect(actual).not_to match(expected)|,
1273
- newline_before_expectation: true,
1274
- expectation: proc {
1275
- line do
1276
- plain %| Expected |
1277
- actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1278
- end
1277
+ program =
1278
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1279
+
1280
+ expected_output =
1281
+ build_expected_output(
1282
+ color_enabled: color_enabled,
1283
+ snippet: "expect(actual).not_to match(expected)",
1284
+ newline_before_expectation: true,
1285
+ expectation:
1286
+ proc do
1287
+ line do
1288
+ plain " Expected "
1289
+ actual %|{ name: "shopping list", contents: ["milk", "toast", "eggs"] }|
1290
+ end
1291
+
1292
+ line do
1293
+ plain "not to match "
1294
+ expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "eggs", "toast")> }|
1295
+ end
1296
+ end
1297
+ )
1279
1298
 
1280
- line do
1281
- plain %|not to match |
1282
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "eggs", "toast")> }|
1283
- end
1284
- },
1299
+ expect(program).to produce_output_when_run(expected_output).in_color(
1300
+ color_enabled
1285
1301
  )
1286
-
1287
- expect(program).
1288
- to produce_output_when_run(expected_output).
1289
- in_color(color_enabled)
1290
1302
  end
1291
1303
  end
1292
1304
  end
1293
1305
 
1294
- context "when the corresponding actual value is not an array" do
1306
+ context "when the corresponding actual value is not an array" do
1295
1307
  it "produces the correct failure message" do
1296
1308
  as_both_colored_and_uncolored do |color_enabled|
1297
1309
  snippet = <<~TEST.strip
@@ -1299,46 +1311,47 @@ RSpec.describe "Integration with RSpec's #match matcher", type: :integration do
1299
1311
  name: "shopping list",
1300
1312
  contents: a_collection_containing_exactly("milk", "bread")
1301
1313
  }
1302
- actual = {
1314
+ actual = {
1303
1315
  name: "shopping list",
1304
1316
  contents: nil
1305
1317
  }
1306
1318
  expect(actual).to match(expected)
1307
1319
  TEST
1308
- program = make_plain_test_program(
1309
- snippet,
1310
- color_enabled: color_enabled,
1311
- )
1312
-
1313
- expected_output = build_expected_output(
1314
- color_enabled: color_enabled,
1315
- snippet: %|expect(actual).to match(expected)|,
1316
- expectation: proc {
1317
- line do
1318
- plain %|Expected |
1319
- actual %|{ name: "shopping list", contents: nil }|
1320
- end
1320
+ program =
1321
+ make_plain_test_program(snippet, color_enabled: color_enabled)
1322
+
1323
+ expected_output =
1324
+ build_expected_output(
1325
+ color_enabled: color_enabled,
1326
+ snippet: "expect(actual).to match(expected)",
1327
+ expectation:
1328
+ proc do
1329
+ line do
1330
+ plain "Expected "
1331
+ actual %|{ name: "shopping list", contents: nil }|
1332
+ end
1333
+
1334
+ line do
1335
+ plain "to match "
1336
+ expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1337
+ end
1338
+ end,
1339
+ diff:
1340
+ proc do
1341
+ plain_line " {"
1342
+ plain_line %! name: "shopping list",!
1343
+ expected_line "- contents: #<a collection containing exactly ("
1344
+ expected_line %!- "milk",!
1345
+ expected_line %!- "bread"!
1346
+ expected_line "- )>"
1347
+ actual_line "+ contents: nil"
1348
+ plain_line " }"
1349
+ end
1350
+ )
1321
1351
 
1322
- line do
1323
- plain %|to match |
1324
- expected %|{ name: "shopping list", contents: #<a collection containing exactly ("milk", "bread")> }|
1325
- end
1326
- },
1327
- diff: proc {
1328
- plain_line %! {!
1329
- plain_line %! name: "shopping list",!
1330
- expected_line %!- contents: #<a collection containing exactly (!
1331
- expected_line %!- "milk",!
1332
- expected_line %!- "bread"!
1333
- expected_line %!- )>!
1334
- actual_line %!+ contents: nil!
1335
- plain_line %! }!
1336
- },
1352
+ expect(program).to produce_output_when_run(expected_output).in_color(
1353
+ color_enabled
1337
1354
  )
1338
-
1339
- expect(program).
1340
- to produce_output_when_run(expected_output).
1341
- in_color(color_enabled)
1342
1355
  end
1343
1356
  end
1344
1357
  end