super_diff 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,77 +1,78 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integration do
3
+ RSpec.describe "Integration with RSpec's #be_<predicate> matcher",
4
+ type: :integration do
4
5
  # rubocop:disable Metrics/BlockLength
5
- ["be", "be_a", "be_an"].each do |prefix|
6
- # rubocop:enable Metrics/BlockLength
6
+ %w[be be_a be_an].each do |prefix|
7
+ # rubocop:enable Metrics/BlockLength
7
8
  context "using #{prefix}_<predicate>" do
8
9
  context "when the predicate method doesn't exist on the object" do
9
- context "when the inspected version of the actual value is short" do
10
+ context "when the inspected version of the actual value is short" do
10
11
  it "produces the correct failure message" do
11
12
  as_both_colored_and_uncolored do |color_enabled|
12
13
  snippet = %|expect(:foo).to #{prefix}_strong|
13
- program = make_plain_test_program(
14
- snippet,
15
- color_enabled: color_enabled,
16
- )
17
-
18
- expected_output = build_expected_output(
19
- color_enabled: color_enabled,
20
- snippet: snippet,
21
- expectation: proc {
22
- line do
23
- plain %|Expected |
24
- actual %|:foo|
25
- plain %| to respond to |
26
- expected %|strong?|
27
- plain %| or |
28
- expected %|strongs?|
29
- plain %|.|
30
- end
31
- },
32
- )
14
+ program =
15
+ make_plain_test_program(snippet, color_enabled: color_enabled)
33
16
 
34
- expect(program).
35
- to produce_output_when_run(expected_output).
36
- in_color(color_enabled)
17
+ expected_output =
18
+ build_expected_output(
19
+ color_enabled: color_enabled,
20
+ snippet: snippet,
21
+ expectation:
22
+ proc do
23
+ line do
24
+ plain "Expected "
25
+ actual ":foo"
26
+ plain " to respond to "
27
+ expected "strong?"
28
+ plain " or "
29
+ expected "strongs?"
30
+ plain "."
31
+ end
32
+ end
33
+ )
34
+
35
+ expect(program).to produce_output_when_run(
36
+ expected_output
37
+ ).in_color(color_enabled)
37
38
  end
38
39
  end
39
40
  end
40
41
 
41
- context "when the inspected version of the actual value is long" do
42
+ context "when the inspected version of the actual value is long" do
42
43
  it "produces the correct failure message" do
43
44
  as_both_colored_and_uncolored do |color_enabled|
44
45
  snippet = <<~TEST.strip
45
46
  hash = { foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }
46
47
  expect(hash).to #{prefix}_strong
47
48
  TEST
48
- program = make_plain_test_program(
49
- snippet,
50
- color_enabled: color_enabled,
51
- )
52
-
53
- expected_output = build_expected_output(
54
- color_enabled: color_enabled,
55
- snippet: %|expect(hash).to #{prefix}_strong|,
56
- newline_before_expectation: true,
57
- expectation: proc {
58
- line do
59
- plain %| Expected |
60
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
61
- end
49
+ program =
50
+ make_plain_test_program(snippet, color_enabled: color_enabled)
62
51
 
63
- line do
64
- plain %|to respond to |
65
- expected %|strong?|
66
- plain %| or |
67
- expected %|strongs?|
68
- end
69
- },
70
- )
52
+ expected_output =
53
+ build_expected_output(
54
+ color_enabled: color_enabled,
55
+ snippet: %|expect(hash).to #{prefix}_strong|,
56
+ newline_before_expectation: true,
57
+ expectation:
58
+ proc do
59
+ line do
60
+ plain " Expected "
61
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
62
+ end
71
63
 
72
- expect(program).
73
- to produce_output_when_run(expected_output).
74
- in_color(color_enabled)
64
+ line do
65
+ plain "to respond to "
66
+ expected "strong?"
67
+ plain " or "
68
+ expected "strongs?"
69
+ end
70
+ end
71
+ )
72
+
73
+ expect(program).to produce_output_when_run(
74
+ expected_output
75
+ ).in_color(color_enabled)
75
76
  end
76
77
  end
77
78
  end
@@ -79,7 +80,7 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
79
80
 
80
81
  context "when the predicate method exists on the object" do
81
82
  context "but is private" do
82
- context "when the inspected version of the actual value is short" do
83
+ context "when the inspected version of the actual value is short" do
83
84
  it "produces the correct failure message" do
84
85
  as_both_colored_and_uncolored do |color_enabled|
85
86
  snippet = <<~TEST.strip
@@ -89,36 +90,35 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
89
90
 
90
91
  expect(Foo.new).to #{prefix}_strong
91
92
  TEST
92
- program = make_plain_test_program(
93
- snippet,
94
- color_enabled: color_enabled,
95
- )
93
+ program =
94
+ make_plain_test_program(snippet, color_enabled: color_enabled)
96
95
 
97
- expected_output = build_expected_output(
98
- color_enabled: color_enabled,
99
- snippet: %|expect(Foo.new).to #{prefix}_strong|,
100
- expectation: proc {
101
- line do
102
- plain %|Expected |
103
- actual %|#<Foo>|
104
- plain %| to have a public method |
105
- expected %|strong?|
106
- plain %| or |
107
- expected %|strongs?|
108
- plain %|.|
109
- end
110
- },
111
- )
96
+ expected_output =
97
+ build_expected_output(
98
+ color_enabled: color_enabled,
99
+ snippet: %|expect(Foo.new).to #{prefix}_strong|,
100
+ expectation:
101
+ proc do
102
+ line do
103
+ plain "Expected "
104
+ actual "#<Foo>"
105
+ plain " to have a public method "
106
+ expected "strong?"
107
+ plain " or "
108
+ expected "strongs?"
109
+ plain "."
110
+ end
111
+ end
112
+ )
112
113
 
113
- expect(program).
114
- to produce_output_when_run(expected_output).
115
- in_color(color_enabled).
116
- removing_object_ids
114
+ expect(program).to produce_output_when_run(
115
+ expected_output
116
+ ).in_color(color_enabled).removing_object_ids
117
117
  end
118
118
  end
119
119
  end
120
120
 
121
- context "when the inspected version of the actual value is long" do
121
+ context "when the inspected version of the actual value is long" do
122
122
  it "produces the correct failure message" do
123
123
  as_both_colored_and_uncolored do |color_enabled|
124
124
  snippet = <<~TEST.strip
@@ -130,34 +130,33 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
130
130
 
131
131
  expect(hash).to #{prefix}_strong
132
132
  TEST
133
- program = make_plain_test_program(
134
- snippet,
135
- color_enabled: color_enabled,
136
- )
133
+ program =
134
+ make_plain_test_program(snippet, color_enabled: color_enabled)
137
135
 
138
- expected_output = build_expected_output(
139
- color_enabled: color_enabled,
140
- snippet: %|expect(hash).to #{prefix}_strong|,
141
- newline_before_expectation: true,
142
- expectation: proc {
143
- line do
144
- plain %| Expected |
145
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
146
- end
136
+ expected_output =
137
+ build_expected_output(
138
+ color_enabled: color_enabled,
139
+ snippet: %|expect(hash).to #{prefix}_strong|,
140
+ newline_before_expectation: true,
141
+ expectation:
142
+ proc do
143
+ line do
144
+ plain " Expected "
145
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
146
+ end
147
147
 
148
- line do
149
- plain %|to have a public method |
150
- expected %|strong?|
151
- plain %| or |
152
- expected %|strongs?|
153
- end
154
- },
155
- )
148
+ line do
149
+ plain "to have a public method "
150
+ expected "strong?"
151
+ plain " or "
152
+ expected "strongs?"
153
+ end
154
+ end
155
+ )
156
156
 
157
- expect(program).
158
- to produce_output_when_run(expected_output).
159
- in_color(color_enabled).
160
- removing_object_ids
157
+ expect(program).to produce_output_when_run(
158
+ expected_output
159
+ ).in_color(color_enabled).removing_object_ids
161
160
  end
162
161
  end
163
162
  end
@@ -166,7 +165,7 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
166
165
  context "and is public" do
167
166
  context "and returns false" do
168
167
  context "but is called #true?" do
169
- context "when the inspected version of the actual value is short" do
168
+ context "when the inspected version of the actual value is short" do
170
169
  it "produces the correct failure message" do
171
170
  as_both_colored_and_uncolored do |color_enabled|
172
171
  snippet = <<~TEST.strip
@@ -176,47 +175,49 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
176
175
 
177
176
  expect(Foo.new).to #{prefix}_true
178
177
  TEST
179
- program = make_plain_test_program(
180
- snippet,
181
- color_enabled: color_enabled,
182
- )
183
-
184
- expected_output = build_expected_output(
185
- color_enabled: color_enabled,
186
- snippet: %|expect(Foo.new).to #{prefix}_true|,
187
- newline_before_expectation: true,
188
- expectation: proc {
189
- line do
190
- plain %|Expected |
191
- actual %|#<Foo>|
192
- plain %| to return a truthy result for |
193
- expected %|true?|
194
- plain %| or |
195
- expected %|trues?|
196
- plain %|.|
197
- end
198
-
199
- newline
178
+ program =
179
+ make_plain_test_program(
180
+ snippet,
181
+ color_enabled: color_enabled
182
+ )
200
183
 
201
- line do
202
- plain %|(Perhaps you want to use |
203
- blue "be(true)"
204
- plain %| or |
205
- blue "be_truthy"
206
- plain %| instead?)|
207
- end
208
- },
209
- )
184
+ expected_output =
185
+ build_expected_output(
186
+ color_enabled: color_enabled,
187
+ snippet: %|expect(Foo.new).to #{prefix}_true|,
188
+ newline_before_expectation: true,
189
+ expectation:
190
+ proc do
191
+ line do
192
+ plain "Expected "
193
+ actual "#<Foo>"
194
+ plain " to return a truthy result for "
195
+ expected "true?"
196
+ plain " or "
197
+ expected "trues?"
198
+ plain "."
199
+ end
200
+
201
+ newline
202
+
203
+ line do
204
+ plain "(Perhaps you want to use "
205
+ blue "be(true)"
206
+ plain " or "
207
+ blue "be_truthy"
208
+ plain " instead?)"
209
+ end
210
+ end
211
+ )
210
212
 
211
- expect(program).
212
- to produce_output_when_run(expected_output).
213
- in_color(color_enabled).
214
- removing_object_ids
213
+ expect(program).to produce_output_when_run(
214
+ expected_output
215
+ ).in_color(color_enabled).removing_object_ids
215
216
  end
216
217
  end
217
218
  end
218
219
 
219
- context "when the inspected version of the actual value is long" do
220
+ context "when the inspected version of the actual value is long" do
220
221
  it "produces the correct failure message" do
221
222
  as_both_colored_and_uncolored do |color_enabled|
222
223
  snippet = <<~TEST.strip
@@ -233,44 +234,46 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
233
234
 
234
235
  expect(hash).to #{prefix}_true
235
236
  TEST
236
- program = make_plain_test_program(
237
- snippet,
238
- color_enabled: color_enabled,
239
- )
240
-
241
- expected_output = build_expected_output(
242
- color_enabled: color_enabled,
243
- snippet: %|expect(hash).to #{prefix}_true|,
244
- newline_before_expectation: true,
245
- expectation: proc {
246
- line do
247
- plain %| Expected |
248
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
249
- end
250
-
251
- line do
252
- plain %|to return a truthy result for |
253
- expected %|true?|
254
- plain %| or |
255
- expected %|trues?|
256
- end
257
-
258
- newline
237
+ program =
238
+ make_plain_test_program(
239
+ snippet,
240
+ color_enabled: color_enabled
241
+ )
259
242
 
260
- line do
261
- plain %|(Perhaps you want to use |
262
- blue "be(true)"
263
- plain %| or |
264
- blue "be_truthy"
265
- plain %| instead?)|
266
- end
267
- },
268
- )
243
+ expected_output =
244
+ build_expected_output(
245
+ color_enabled: color_enabled,
246
+ snippet: %|expect(hash).to #{prefix}_true|,
247
+ newline_before_expectation: true,
248
+ expectation:
249
+ proc do
250
+ line do
251
+ plain " Expected "
252
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz" }|
253
+ end
254
+
255
+ line do
256
+ plain "to return a truthy result for "
257
+ expected "true?"
258
+ plain " or "
259
+ expected "trues?"
260
+ end
261
+
262
+ newline
263
+
264
+ line do
265
+ plain "(Perhaps you want to use "
266
+ blue "be(true)"
267
+ plain " or "
268
+ blue "be_truthy"
269
+ plain " instead?)"
270
+ end
271
+ end
272
+ )
269
273
 
270
- expect(program).
271
- to produce_output_when_run(expected_output).
272
- in_color(color_enabled).
273
- removing_object_ids
274
+ expect(program).to produce_output_when_run(
275
+ expected_output
276
+ ).in_color(color_enabled).removing_object_ids
274
277
  end
275
278
  end
276
279
  end
@@ -286,39 +289,41 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
286
289
 
287
290
  expect(X.new).to #{prefix}_false
288
291
  TEST
289
- program = make_plain_test_program(
290
- snippet,
291
- color_enabled: color_enabled,
292
- )
292
+ program =
293
+ make_plain_test_program(
294
+ snippet,
295
+ color_enabled: color_enabled
296
+ )
293
297
 
294
- expected_output = build_expected_output(
295
- color_enabled: color_enabled,
296
- snippet: %|expect(X.new).to #{prefix}_false|,
297
- newline_before_expectation: true,
298
- expectation: proc {
299
- line do
300
- plain %|Expected |
301
- actual %|#<X>|
302
- plain %| to return a truthy result for |
303
- expected %|false?|
304
- plain %| or |
305
- expected %|falses?|
306
- plain %|.|
307
- end
308
- },
309
- )
298
+ expected_output =
299
+ build_expected_output(
300
+ color_enabled: color_enabled,
301
+ snippet: %|expect(X.new).to #{prefix}_false|,
302
+ newline_before_expectation: true,
303
+ expectation:
304
+ proc do
305
+ line do
306
+ plain "Expected "
307
+ actual "#<X>"
308
+ plain " to return a truthy result for "
309
+ expected "false?"
310
+ plain " or "
311
+ expected "falses?"
312
+ plain "."
313
+ end
314
+ end
315
+ )
310
316
 
311
- expect(program).
312
- to produce_output_when_run(expected_output).
313
- in_color(color_enabled).
314
- removing_object_ids
317
+ expect(program).to produce_output_when_run(
318
+ expected_output
319
+ ).in_color(color_enabled).removing_object_ids
315
320
  end
316
321
  end
317
322
  end
318
323
 
319
324
  context "and is called neither #true? nor #false?" do
320
325
  context "and is singular" do
321
- context "when the inspected version of the actual value is short" do
326
+ context "when the inspected version of the actual value is short" do
322
327
  it "produces the correct failure message" do
323
328
  as_both_colored_and_uncolored do |color_enabled|
324
329
  snippet = <<~TEST.strip
@@ -328,36 +333,38 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
328
333
 
329
334
  expect(X.new).to #{prefix}_y
330
335
  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(X.new).to #{prefix}_y|,
339
- expectation: proc {
340
- line do
341
- plain %|Expected |
342
- actual %|#<X>|
343
- plain %| to return a truthy result for |
344
- expected %|y?|
345
- plain %| or |
346
- expected %|ys?|
347
- plain %|.|
348
- end
349
- },
350
- )
351
-
352
- expect(program).
353
- to produce_output_when_run(expected_output).
354
- in_color(color_enabled).
355
- removing_object_ids
336
+ program =
337
+ make_plain_test_program(
338
+ snippet,
339
+ color_enabled: color_enabled
340
+ )
341
+
342
+ expected_output =
343
+ build_expected_output(
344
+ color_enabled: color_enabled,
345
+ snippet: %|expect(X.new).to #{prefix}_y|,
346
+ expectation:
347
+ proc do
348
+ line do
349
+ plain "Expected "
350
+ actual "#<X>"
351
+ plain " to return a truthy result for "
352
+ expected "y?"
353
+ plain " or "
354
+ expected "ys?"
355
+ plain "."
356
+ end
357
+ end
358
+ )
359
+
360
+ expect(program).to produce_output_when_run(
361
+ expected_output
362
+ ).in_color(color_enabled).removing_object_ids
356
363
  end
357
364
  end
358
365
  end
359
366
 
360
- context "when the inspected version of the actual value is long" do
367
+ context "when the inspected version of the actual value is long" do
361
368
  it "produces the correct failure message" do
362
369
  as_both_colored_and_uncolored do |color_enabled|
363
370
  snippet = <<~TEST.strip
@@ -375,41 +382,43 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
375
382
 
376
383
  expect(hash).to #{prefix}_y
377
384
  TEST
378
- program = make_plain_test_program(
379
- snippet,
380
- color_enabled: color_enabled,
381
- )
382
-
383
- expected_output = build_expected_output(
384
- color_enabled: color_enabled,
385
- snippet: %|expect(hash).to #{prefix}_y|,
386
- newline_before_expectation: true,
387
- expectation: proc {
388
- line do
389
- plain %| Expected |
390
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
391
- end
392
-
393
- line do
394
- plain %|to return a truthy result for |
395
- expected %|y?|
396
- plain %| or |
397
- expected %|ys?|
398
- end
399
- },
400
- )
401
-
402
- expect(program).
403
- to produce_output_when_run(expected_output).
404
- in_color(color_enabled).
405
- removing_object_ids
385
+ program =
386
+ make_plain_test_program(
387
+ snippet,
388
+ color_enabled: color_enabled
389
+ )
390
+
391
+ expected_output =
392
+ build_expected_output(
393
+ color_enabled: color_enabled,
394
+ snippet: %|expect(hash).to #{prefix}_y|,
395
+ newline_before_expectation: true,
396
+ expectation:
397
+ proc do
398
+ line do
399
+ plain " Expected "
400
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
401
+ end
402
+
403
+ line do
404
+ plain "to return a truthy result for "
405
+ expected "y?"
406
+ plain " or "
407
+ expected "ys?"
408
+ end
409
+ end
410
+ )
411
+
412
+ expect(program).to produce_output_when_run(
413
+ expected_output
414
+ ).in_color(color_enabled).removing_object_ids
406
415
  end
407
416
  end
408
417
  end
409
418
  end
410
419
 
411
420
  context "and is plural" do
412
- context "when the inspected version of the actual value is short" do
421
+ context "when the inspected version of the actual value is short" do
413
422
  it "produces the correct failure message" do
414
423
  as_both_colored_and_uncolored do |color_enabled|
415
424
  snippet = <<~TEST.strip
@@ -419,36 +428,38 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
419
428
 
420
429
  expect(X.new).to #{prefix}_y
421
430
  TEST
422
- program = make_plain_test_program(
423
- snippet,
424
- color_enabled: color_enabled,
425
- )
426
-
427
- expected_output = build_expected_output(
428
- color_enabled: color_enabled,
429
- snippet: %|expect(X.new).to #{prefix}_y|,
430
- expectation: proc {
431
- line do
432
- plain %|Expected |
433
- actual %|#<X>|
434
- plain %| to return a truthy result for |
435
- expected %|y?|
436
- plain %| or |
437
- expected %|ys?|
438
- plain %|.|
439
- end
440
- },
441
- )
442
-
443
- expect(program).
444
- to produce_output_when_run(expected_output).
445
- in_color(color_enabled).
446
- removing_object_ids
431
+ program =
432
+ make_plain_test_program(
433
+ snippet,
434
+ color_enabled: color_enabled
435
+ )
436
+
437
+ expected_output =
438
+ build_expected_output(
439
+ color_enabled: color_enabled,
440
+ snippet: %|expect(X.new).to #{prefix}_y|,
441
+ expectation:
442
+ proc do
443
+ line do
444
+ plain "Expected "
445
+ actual "#<X>"
446
+ plain " to return a truthy result for "
447
+ expected "y?"
448
+ plain " or "
449
+ expected "ys?"
450
+ plain "."
451
+ end
452
+ end
453
+ )
454
+
455
+ expect(program).to produce_output_when_run(
456
+ expected_output
457
+ ).in_color(color_enabled).removing_object_ids
447
458
  end
448
459
  end
449
460
  end
450
461
 
451
- context "when the inspected version of the actual value is long" do
462
+ context "when the inspected version of the actual value is long" do
452
463
  it "produces the correct failure message" do
453
464
  as_both_colored_and_uncolored do |color_enabled|
454
465
  snippet = <<~TEST.strip
@@ -466,34 +477,36 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
466
477
 
467
478
  expect(hash).to #{prefix}_y
468
479
  TEST
469
- program = make_plain_test_program(
470
- snippet,
471
- color_enabled: color_enabled,
472
- )
473
-
474
- expected_output = build_expected_output(
475
- color_enabled: color_enabled,
476
- snippet: %|expect(hash).to #{prefix}_y|,
477
- newline_before_expectation: true,
478
- expectation: proc {
479
- line do
480
- plain %| Expected |
481
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
482
- end
483
-
484
- line do
485
- plain %|to return a truthy result for |
486
- expected %|y?|
487
- plain %| or |
488
- expected %|ys?|
489
- end
490
- },
491
- )
492
-
493
- expect(program).
494
- to produce_output_when_run(expected_output).
495
- in_color(color_enabled).
496
- removing_object_ids
480
+ program =
481
+ make_plain_test_program(
482
+ snippet,
483
+ color_enabled: color_enabled
484
+ )
485
+
486
+ expected_output =
487
+ build_expected_output(
488
+ color_enabled: color_enabled,
489
+ snippet: %|expect(hash).to #{prefix}_y|,
490
+ newline_before_expectation: true,
491
+ expectation:
492
+ proc do
493
+ line do
494
+ plain " Expected "
495
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
496
+ end
497
+
498
+ line do
499
+ plain "to return a truthy result for "
500
+ expected "y?"
501
+ plain " or "
502
+ expected "ys?"
503
+ end
504
+ end
505
+ )
506
+
507
+ expect(program).to produce_output_when_run(
508
+ expected_output
509
+ ).in_color(color_enabled).removing_object_ids
497
510
  end
498
511
  end
499
512
  end
@@ -502,7 +515,7 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
502
515
  end
503
516
 
504
517
  context "and returns true" do
505
- context "when the inspected version of the actual value is short" do
518
+ context "when the inspected version of the actual value is short" do
506
519
  it "produces the correct failure message when used in the negative" do
507
520
  as_both_colored_and_uncolored do |color_enabled|
508
521
  snippet = <<~TEST.strip
@@ -512,36 +525,38 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
512
525
 
513
526
  expect(Foo.new).not_to #{prefix}_strong
514
527
  TEST
515
- program = make_plain_test_program(
516
- snippet,
517
- color_enabled: color_enabled,
518
- )
528
+ program =
529
+ make_plain_test_program(
530
+ snippet,
531
+ color_enabled: color_enabled
532
+ )
519
533
 
520
- expected_output = build_expected_output(
521
- color_enabled: color_enabled,
522
- snippet: %|expect(Foo.new).not_to #{prefix}_strong|,
523
- expectation: proc {
524
- line do
525
- plain %|Expected |
526
- actual %|#<Foo>|
527
- plain %| not to return a truthy result for |
528
- expected %|strong?|
529
- plain %| or |
530
- expected %|strongs?|
531
- plain %|.|
532
- end
533
- },
534
- )
534
+ expected_output =
535
+ build_expected_output(
536
+ color_enabled: color_enabled,
537
+ snippet: %|expect(Foo.new).not_to #{prefix}_strong|,
538
+ expectation:
539
+ proc do
540
+ line do
541
+ plain "Expected "
542
+ actual "#<Foo>"
543
+ plain " not to return a truthy result for "
544
+ expected "strong?"
545
+ plain " or "
546
+ expected "strongs?"
547
+ plain "."
548
+ end
549
+ end
550
+ )
535
551
 
536
- expect(program).
537
- to produce_output_when_run(expected_output).
538
- in_color(color_enabled).
539
- removing_object_ids
552
+ expect(program).to produce_output_when_run(
553
+ expected_output
554
+ ).in_color(color_enabled).removing_object_ids
540
555
  end
541
556
  end
542
557
  end
543
558
 
544
- context "when the inspected version of the actual value is long" do
559
+ context "when the inspected version of the actual value is long" do
545
560
  it "produces the correct failure message when used in the negative" do
546
561
  as_both_colored_and_uncolored do |color_enabled|
547
562
  snippet = <<~TEST.strip
@@ -559,34 +574,36 @@ RSpec.describe "Integration with RSpec's #be_<predicate> matcher", type: :integr
559
574
 
560
575
  expect(hash).not_to #{prefix}_y
561
576
  TEST
562
- program = make_plain_test_program(
563
- snippet,
564
- color_enabled: color_enabled,
565
- )
577
+ program =
578
+ make_plain_test_program(
579
+ snippet,
580
+ color_enabled: color_enabled
581
+ )
566
582
 
567
- expected_output = build_expected_output(
568
- color_enabled: color_enabled,
569
- snippet: %|expect(hash).not_to #{prefix}_y|,
570
- newline_before_expectation: true,
571
- expectation: proc {
572
- line do
573
- plain %| Expected |
574
- actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
575
- end
583
+ expected_output =
584
+ build_expected_output(
585
+ color_enabled: color_enabled,
586
+ snippet: %|expect(hash).not_to #{prefix}_y|,
587
+ newline_before_expectation: true,
588
+ expectation:
589
+ proc do
590
+ line do
591
+ plain " Expected "
592
+ actual %|{ foo: "bar", baz: "qux", blargh: "foz", fizz: "buzz", aaaaaa: "bbbbbb" }|
593
+ end
576
594
 
577
- line do
578
- plain %|not to return a truthy result for |
579
- expected %|y?|
580
- plain %| or |
581
- expected %|ys?|
582
- end
583
- },
584
- )
595
+ line do
596
+ plain "not to return a truthy result for "
597
+ expected "y?"
598
+ plain " or "
599
+ expected "ys?"
600
+ end
601
+ end
602
+ )
585
603
 
586
- expect(program).
587
- to produce_output_when_run(expected_output).
588
- in_color(color_enabled).
589
- removing_object_ids
604
+ expect(program).to produce_output_when_run(
605
+ expected_output
606
+ ).in_color(color_enabled).removing_object_ids
590
607
  end
591
608
  end
592
609
  end