super_diff 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) 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 +11 -7
  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 +5 -9
  128. data/spec/examples.txt +493 -407
  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 +27 -20
  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 +70 -68
@@ -1,69 +1,70 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :integration do
3
+ RSpec.describe "Integration with RSpec's #have_<predicate> matcher",
4
+ type: :integration do
4
5
  context "when the predicate method doesn't exist on the object" do
5
6
  context "when the predicate method doesn't exist on the object" do
6
7
  it "produces the correct failure message" do
7
8
  as_both_colored_and_uncolored do |color_enabled|
8
- snippet = %|expect(:words).to have_power|
9
- program = make_plain_test_program(
10
- snippet,
11
- color_enabled: color_enabled,
12
- )
9
+ snippet = "expect(:words).to have_power"
10
+ program =
11
+ make_plain_test_program(snippet, color_enabled: color_enabled)
13
12
 
14
- expected_output = build_expected_output(
15
- color_enabled: color_enabled,
16
- snippet: snippet,
17
- expectation: proc {
18
- line do
19
- plain %|Expected |
20
- actual %|:words|
21
- plain %| to respond to |
22
- expected %|has_power?|
23
- plain %|.|
24
- end
25
- },
26
- )
13
+ expected_output =
14
+ build_expected_output(
15
+ color_enabled: color_enabled,
16
+ snippet: snippet,
17
+ expectation:
18
+ proc do
19
+ line do
20
+ plain "Expected "
21
+ actual ":words"
22
+ plain " to respond to "
23
+ expected "has_power?"
24
+ plain "."
25
+ end
26
+ end
27
+ )
27
28
 
28
- expect(program).
29
- to produce_output_when_run(expected_output).
30
- in_color(color_enabled)
29
+ expect(program).to produce_output_when_run(expected_output).in_color(
30
+ color_enabled
31
+ )
31
32
  end
32
33
  end
33
34
  end
34
35
 
35
- context "when the inspected version of the actual value is long" do
36
+ context "when the inspected version of the actual value is long" do
36
37
  it "produces the correct failure message" do
37
38
  as_both_colored_and_uncolored do |color_enabled|
38
39
  snippet = <<~TEST.strip
39
40
  hash = { a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }
40
41
  expect(hash).to have_mapping
41
42
  TEST
42
- program = make_plain_test_program(
43
- snippet,
44
- color_enabled: color_enabled,
45
- )
43
+ program =
44
+ make_plain_test_program(snippet, color_enabled: color_enabled)
46
45
 
47
- expected_output = build_expected_output(
48
- color_enabled: color_enabled,
49
- snippet: %|expect(hash).to have_mapping|,
50
- newline_before_expectation: true,
51
- expectation: proc {
52
- line do
53
- plain %| Expected |
54
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
55
- end
46
+ expected_output =
47
+ build_expected_output(
48
+ color_enabled: color_enabled,
49
+ snippet: "expect(hash).to have_mapping",
50
+ newline_before_expectation: true,
51
+ expectation:
52
+ proc do
53
+ line do
54
+ plain " Expected "
55
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
56
+ end
56
57
 
57
- line do
58
- plain %|to respond to |
59
- expected %|has_mapping?|
60
- end
61
- },
62
- )
58
+ line do
59
+ plain "to respond to "
60
+ expected "has_mapping?"
61
+ end
62
+ end
63
+ )
63
64
 
64
- expect(program).
65
- to produce_output_when_run(expected_output).
66
- in_color(color_enabled)
65
+ expect(program).to produce_output_when_run(expected_output).in_color(
66
+ color_enabled
67
+ )
67
68
  end
68
69
  end
69
70
  end
@@ -71,7 +72,7 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
71
72
 
72
73
  context "when the predicate method exists on the object" do
73
74
  context "but is private" do
74
- context "when the inspected version of the actual value is short" do
75
+ context "when the inspected version of the actual value is short" do
75
76
  it "produces the correct failure message" do
76
77
  as_both_colored_and_uncolored do |color_enabled|
77
78
  snippet = <<~TEST.strip
@@ -81,34 +82,33 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
81
82
 
82
83
  expect(Robot.new).to have_arms
83
84
  TEST
84
- program = make_plain_test_program(
85
- snippet,
86
- color_enabled: color_enabled,
87
- )
88
-
89
- expected_output = build_expected_output(
90
- color_enabled: color_enabled,
91
- snippet: %|expect(Robot.new).to have_arms|,
92
- expectation: proc {
93
- line do
94
- plain %|Expected |
95
- actual %|#<Robot>|
96
- plain %| to have a public method |
97
- expected %|has_arms?|
98
- plain %|.|
99
- end
100
- },
101
- )
85
+ program =
86
+ make_plain_test_program(snippet, color_enabled: color_enabled)
87
+
88
+ expected_output =
89
+ build_expected_output(
90
+ color_enabled: color_enabled,
91
+ snippet: "expect(Robot.new).to have_arms",
92
+ expectation:
93
+ proc do
94
+ line do
95
+ plain "Expected "
96
+ actual "#<Robot>"
97
+ plain " to have a public method "
98
+ expected "has_arms?"
99
+ plain "."
100
+ end
101
+ end
102
+ )
102
103
 
103
- expect(program).
104
- to produce_output_when_run(expected_output).
105
- in_color(color_enabled).
106
- removing_object_ids
104
+ expect(program).to produce_output_when_run(
105
+ expected_output
106
+ ).in_color(color_enabled).removing_object_ids
107
107
  end
108
108
  end
109
109
  end
110
110
 
111
- context "when the inspected version of the actual value is long" do
111
+ context "when the inspected version of the actual value is long" do
112
112
  it "produces the correct failure message" do
113
113
  as_both_colored_and_uncolored do |color_enabled|
114
114
  snippet = <<~TEST.strip
@@ -120,32 +120,31 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
120
120
 
121
121
  expect(hash).to have_mapping
122
122
  TEST
123
- program = make_plain_test_program(
124
- snippet,
125
- color_enabled: color_enabled,
126
- )
127
-
128
- expected_output = build_expected_output(
129
- color_enabled: color_enabled,
130
- snippet: %|expect(hash).to have_mapping|,
131
- newline_before_expectation: true,
132
- expectation: proc {
133
- line do
134
- plain %| Expected |
135
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
136
- end
123
+ program =
124
+ make_plain_test_program(snippet, color_enabled: color_enabled)
125
+
126
+ expected_output =
127
+ build_expected_output(
128
+ color_enabled: color_enabled,
129
+ snippet: "expect(hash).to have_mapping",
130
+ newline_before_expectation: true,
131
+ expectation:
132
+ proc do
133
+ line do
134
+ plain " Expected "
135
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
136
+ end
137
137
 
138
- line do
139
- plain %|to have a public method |
140
- expected %|has_mapping?|
141
- end
142
- },
143
- )
138
+ line do
139
+ plain "to have a public method "
140
+ expected "has_mapping?"
141
+ end
142
+ end
143
+ )
144
144
 
145
- expect(program).
146
- to produce_output_when_run(expected_output).
147
- in_color(color_enabled).
148
- removing_object_ids
145
+ expect(program).to produce_output_when_run(
146
+ expected_output
147
+ ).in_color(color_enabled).removing_object_ids
149
148
  end
150
149
  end
151
150
  end
@@ -154,7 +153,7 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
154
153
  context "and is public" do
155
154
  context "and returns false" do
156
155
  context "and takes arguments" do
157
- context "when the inspected version of the actual value is short" do
156
+ context "when the inspected version of the actual value is short" do
158
157
  it "produces the correct failure message" do
159
158
  as_both_colored_and_uncolored do |color_enabled|
160
159
  snippet = <<~TEST.strip
@@ -164,34 +163,33 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
164
163
 
165
164
  expect(Drink.new).to have_ingredients(:vodka)
166
165
  TEST
167
- program = make_plain_test_program(
168
- snippet,
169
- color_enabled: color_enabled,
170
- )
171
-
172
- expected_output = build_expected_output(
173
- color_enabled: color_enabled,
174
- snippet: %|expect(Drink.new).to have_ingredients(:vodka)|,
175
- expectation: proc {
176
- line do
177
- plain %|Expected |
178
- actual %|#<Drink>|
179
- plain %| to return a truthy result for |
180
- expected %|has_ingredients?(:vodka)|
181
- plain %|.|
182
- end
183
- },
184
- )
185
-
186
- expect(program).
187
- to produce_output_when_run(expected_output).
188
- in_color(color_enabled).
189
- removing_object_ids
166
+ program =
167
+ make_plain_test_program(snippet, color_enabled: color_enabled)
168
+
169
+ expected_output =
170
+ build_expected_output(
171
+ color_enabled: color_enabled,
172
+ snippet: "expect(Drink.new).to have_ingredients(:vodka)",
173
+ expectation:
174
+ proc do
175
+ line do
176
+ plain "Expected "
177
+ actual "#<Drink>"
178
+ plain " to return a truthy result for "
179
+ expected "has_ingredients?(:vodka)"
180
+ plain "."
181
+ end
182
+ end
183
+ )
184
+
185
+ expect(program).to produce_output_when_run(
186
+ expected_output
187
+ ).in_color(color_enabled).removing_object_ids
190
188
  end
191
189
  end
192
190
  end
193
191
 
194
- context "when the inspected version of the actual value is long" do
192
+ context "when the inspected version of the actual value is long" do
195
193
  it "produces the correct failure message" do
196
194
  as_both_colored_and_uncolored do |color_enabled|
197
195
  snippet = <<~TEST.strip
@@ -203,39 +201,39 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
203
201
 
204
202
  expect(hash).to have_contents("keys", "upon", "keys")
205
203
  TEST
206
- program = make_plain_test_program(
207
- snippet,
208
- color_enabled: color_enabled,
209
- )
210
-
211
- expected_output = build_expected_output(
212
- color_enabled: color_enabled,
213
- snippet: %|expect(hash).to have_contents("keys", "upon", "keys")|,
214
- newline_before_expectation: true,
215
- expectation: proc {
216
- line do
217
- plain %| Expected |
218
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
219
- end
220
-
221
- line do
222
- plain %|to return a truthy result for |
223
- expected %|has_contents?("keys", "upon", "keys")|
224
- end
225
- },
226
- )
227
-
228
- expect(program).
229
- to produce_output_when_run(expected_output).
230
- in_color(color_enabled).
231
- removing_object_ids
204
+ program =
205
+ make_plain_test_program(snippet, color_enabled: color_enabled)
206
+
207
+ expected_output =
208
+ build_expected_output(
209
+ color_enabled: color_enabled,
210
+ snippet:
211
+ %|expect(hash).to have_contents("keys", "upon", "keys")|,
212
+ newline_before_expectation: true,
213
+ expectation:
214
+ proc do
215
+ line do
216
+ plain " Expected "
217
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
218
+ end
219
+
220
+ line do
221
+ plain "to return a truthy result for "
222
+ expected %|has_contents?("keys", "upon", "keys")|
223
+ end
224
+ end
225
+ )
226
+
227
+ expect(program).to produce_output_when_run(
228
+ expected_output
229
+ ).in_color(color_enabled).removing_object_ids
232
230
  end
233
231
  end
234
232
  end
235
233
  end
236
234
 
237
235
  context "and takes no arguments" do
238
- context "when the inspected version of the actual value is short" do
236
+ context "when the inspected version of the actual value is short" do
239
237
  it "produces the correct failure message" do
240
238
  as_both_colored_and_uncolored do |color_enabled|
241
239
  snippet = <<~TEST.strip
@@ -245,34 +243,33 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
245
243
 
246
244
  expect(Robot.new).to have_arms
247
245
  TEST
248
- program = make_plain_test_program(
249
- snippet,
250
- color_enabled: color_enabled,
251
- )
252
-
253
- expected_output = build_expected_output(
254
- color_enabled: color_enabled,
255
- snippet: %|expect(Robot.new).to have_arms|,
256
- expectation: proc {
257
- line do
258
- plain %|Expected |
259
- actual %|#<Robot>|
260
- plain %| to return a truthy result for |
261
- expected %|has_arms?|
262
- plain %|.|
263
- end
264
- },
265
- )
266
-
267
- expect(program).
268
- to produce_output_when_run(expected_output).
269
- in_color(color_enabled).
270
- removing_object_ids
246
+ program =
247
+ make_plain_test_program(snippet, color_enabled: color_enabled)
248
+
249
+ expected_output =
250
+ build_expected_output(
251
+ color_enabled: color_enabled,
252
+ snippet: "expect(Robot.new).to have_arms",
253
+ expectation:
254
+ proc do
255
+ line do
256
+ plain "Expected "
257
+ actual "#<Robot>"
258
+ plain " to return a truthy result for "
259
+ expected "has_arms?"
260
+ plain "."
261
+ end
262
+ end
263
+ )
264
+
265
+ expect(program).to produce_output_when_run(
266
+ expected_output
267
+ ).in_color(color_enabled).removing_object_ids
271
268
  end
272
269
  end
273
270
  end
274
271
 
275
- context "when the inspected version of the actual value is long" do
272
+ context "when the inspected version of the actual value is long" do
276
273
  it "produces the correct failure message" do
277
274
  as_both_colored_and_uncolored do |color_enabled|
278
275
  snippet = <<~TEST.strip
@@ -284,32 +281,31 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
284
281
 
285
282
  expect(hash).to have_mapping
286
283
  TEST
287
- program = make_plain_test_program(
288
- snippet,
289
- color_enabled: color_enabled,
290
- )
291
-
292
- expected_output = build_expected_output(
293
- color_enabled: color_enabled,
294
- snippet: %|expect(hash).to have_mapping|,
295
- newline_before_expectation: true,
296
- expectation: proc {
297
- line do
298
- plain %| Expected |
299
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
300
- end
301
-
302
- line do
303
- plain %|to return a truthy result for |
304
- expected %|has_mapping?|
305
- end
306
- },
307
- )
308
-
309
- expect(program).
310
- to produce_output_when_run(expected_output).
311
- in_color(color_enabled).
312
- removing_object_ids
284
+ program =
285
+ make_plain_test_program(snippet, color_enabled: color_enabled)
286
+
287
+ expected_output =
288
+ build_expected_output(
289
+ color_enabled: color_enabled,
290
+ snippet: "expect(hash).to have_mapping",
291
+ newline_before_expectation: true,
292
+ expectation:
293
+ proc do
294
+ line do
295
+ plain " Expected "
296
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
297
+ end
298
+
299
+ line do
300
+ plain "to return a truthy result for "
301
+ expected "has_mapping?"
302
+ end
303
+ end
304
+ )
305
+
306
+ expect(program).to produce_output_when_run(
307
+ expected_output
308
+ ).in_color(color_enabled).removing_object_ids
313
309
  end
314
310
  end
315
311
  end
@@ -318,7 +314,7 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
318
314
 
319
315
  context "and returns true" do
320
316
  context "and takes arguments" do
321
- context "when the inspected version of the actual value is short" do
317
+ context "when the inspected version of the actual value is short" do
322
318
  it "produces the correct failure message" do
323
319
  as_both_colored_and_uncolored do |color_enabled|
324
320
  snippet = <<~TEST.strip
@@ -328,34 +324,34 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
328
324
 
329
325
  expect(Drink.new).not_to have_ingredients(:vodka)
330
326
  TEST
331
- program = make_plain_test_program(
332
- snippet,
333
- color_enabled: color_enabled,
334
- )
335
-
336
- expected_output = build_expected_output(
337
- color_enabled: color_enabled,
338
- snippet: %|expect(Drink.new).not_to have_ingredients(:vodka)|,
339
- expectation: proc {
340
- line do
341
- plain %|Expected |
342
- actual %|#<Drink>|
343
- plain %| not to return a truthy result for |
344
- expected %|has_ingredients?(:vodka)|
345
- plain %|.|
346
- end
347
- },
348
- )
349
-
350
- expect(program).
351
- to produce_output_when_run(expected_output).
352
- in_color(color_enabled).
353
- removing_object_ids
327
+ program =
328
+ make_plain_test_program(snippet, color_enabled: color_enabled)
329
+
330
+ expected_output =
331
+ build_expected_output(
332
+ color_enabled: color_enabled,
333
+ snippet:
334
+ "expect(Drink.new).not_to have_ingredients(:vodka)",
335
+ expectation:
336
+ proc do
337
+ line do
338
+ plain "Expected "
339
+ actual "#<Drink>"
340
+ plain " not to return a truthy result for "
341
+ expected "has_ingredients?(:vodka)"
342
+ plain "."
343
+ end
344
+ end
345
+ )
346
+
347
+ expect(program).to produce_output_when_run(
348
+ expected_output
349
+ ).in_color(color_enabled).removing_object_ids
354
350
  end
355
351
  end
356
352
  end
357
353
 
358
- context "when the inspected version of the actual value is long" do
354
+ context "when the inspected version of the actual value is long" do
359
355
  it "produces the correct failure message" do
360
356
  as_both_colored_and_uncolored do |color_enabled|
361
357
  snippet = <<~TEST.strip
@@ -367,39 +363,39 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
367
363
 
368
364
  expect(hash).not_to have_contents("keys", "upon", "keys")
369
365
  TEST
370
- program = make_plain_test_program(
371
- snippet,
372
- color_enabled: color_enabled,
373
- )
374
-
375
- expected_output = build_expected_output(
376
- color_enabled: color_enabled,
377
- snippet: %|expect(hash).not_to have_contents("keys", "upon", "keys")|,
378
- newline_before_expectation: true,
379
- expectation: proc {
380
- line do
381
- plain %| Expected |
382
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
383
- end
384
-
385
- line do
386
- plain %|not to return a truthy result for |
387
- expected %|has_contents?("keys", "upon", "keys")|
388
- end
389
- },
390
- )
391
-
392
- expect(program).
393
- to produce_output_when_run(expected_output).
394
- in_color(color_enabled).
395
- removing_object_ids
366
+ program =
367
+ make_plain_test_program(snippet, color_enabled: color_enabled)
368
+
369
+ expected_output =
370
+ build_expected_output(
371
+ color_enabled: color_enabled,
372
+ snippet:
373
+ %|expect(hash).not_to have_contents("keys", "upon", "keys")|,
374
+ newline_before_expectation: true,
375
+ expectation:
376
+ proc do
377
+ line do
378
+ plain " Expected "
379
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
380
+ end
381
+
382
+ line do
383
+ plain "not to return a truthy result for "
384
+ expected %|has_contents?("keys", "upon", "keys")|
385
+ end
386
+ end
387
+ )
388
+
389
+ expect(program).to produce_output_when_run(
390
+ expected_output
391
+ ).in_color(color_enabled).removing_object_ids
396
392
  end
397
393
  end
398
394
  end
399
395
  end
400
396
 
401
397
  context "and takes no arguments" do
402
- context "when the inspected version of the actual value is short" do
398
+ context "when the inspected version of the actual value is short" do
403
399
  it "produces the correct failure message when used in the negative" do
404
400
  as_both_colored_and_uncolored do |color_enabled|
405
401
  snippet = <<~TEST.strip
@@ -409,34 +405,33 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
409
405
 
410
406
  expect(Robot.new).not_to have_arms
411
407
  TEST
412
- program = make_plain_test_program(
413
- snippet,
414
- color_enabled: color_enabled,
415
- )
416
-
417
- expected_output = build_expected_output(
418
- color_enabled: color_enabled,
419
- snippet: %|expect(Robot.new).not_to have_arms|,
420
- expectation: proc {
421
- line do
422
- plain %|Expected |
423
- actual %|#<Robot>|
424
- plain %| not to return a truthy result for |
425
- expected %|has_arms?|
426
- plain %|.|
427
- end
428
- },
429
- )
430
-
431
- expect(program).
432
- to produce_output_when_run(expected_output).
433
- in_color(color_enabled).
434
- removing_object_ids
408
+ program =
409
+ make_plain_test_program(snippet, color_enabled: color_enabled)
410
+
411
+ expected_output =
412
+ build_expected_output(
413
+ color_enabled: color_enabled,
414
+ snippet: "expect(Robot.new).not_to have_arms",
415
+ expectation:
416
+ proc do
417
+ line do
418
+ plain "Expected "
419
+ actual "#<Robot>"
420
+ plain " not to return a truthy result for "
421
+ expected "has_arms?"
422
+ plain "."
423
+ end
424
+ end
425
+ )
426
+
427
+ expect(program).to produce_output_when_run(
428
+ expected_output
429
+ ).in_color(color_enabled).removing_object_ids
435
430
  end
436
431
  end
437
432
  end
438
433
 
439
- context "when the inspected version of the actual value is long" do
434
+ context "when the inspected version of the actual value is long" do
440
435
  it "produces the correct failure message when used in the negative" do
441
436
  as_both_colored_and_uncolored do |color_enabled|
442
437
  snippet = <<~TEST.strip
@@ -448,32 +443,31 @@ RSpec.describe "Integration with RSpec's #have_<predicate> matcher", type: :inte
448
443
 
449
444
  expect(hash).not_to have_mapping
450
445
  TEST
451
- program = make_plain_test_program(
452
- snippet,
453
- color_enabled: color_enabled,
454
- )
455
-
456
- expected_output = build_expected_output(
457
- color_enabled: color_enabled,
458
- snippet: %|expect(hash).not_to have_mapping|,
459
- newline_before_expectation: true,
460
- expectation: proc {
461
- line do
462
- plain %| Expected |
463
- actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
464
- end
465
-
466
- line do
467
- plain %|not to return a truthy result for |
468
- expected %|has_mapping?|
469
- end
470
- },
471
- )
472
-
473
- expect(program).
474
- to produce_output_when_run(expected_output).
475
- in_color(color_enabled).
476
- removing_object_ids
446
+ program =
447
+ make_plain_test_program(snippet, color_enabled: color_enabled)
448
+
449
+ expected_output =
450
+ build_expected_output(
451
+ color_enabled: color_enabled,
452
+ snippet: "expect(hash).not_to have_mapping",
453
+ newline_before_expectation: true,
454
+ expectation:
455
+ proc do
456
+ line do
457
+ plain " Expected "
458
+ actual %|{ a: "lot", of: "keys", and: "things", like: "that", lets: "add", more: "keys" }|
459
+ end
460
+
461
+ line do
462
+ plain "not to return a truthy result for "
463
+ expected "has_mapping?"
464
+ end
465
+ end
466
+ )
467
+
468
+ expect(program).to produce_output_when_run(
469
+ expected_output
470
+ ).in_color(color_enabled).removing_object_ids
477
471
  end
478
472
  end
479
473
  end