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,46 +1,48 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe "Integration with RSpec's #include matcher", type: :integration do
3
+ RSpec.describe "Integration with RSpec's #include matcher",
4
+ type: :integration do
4
5
  context "when used against an array" do
5
6
  context "that is small" do
6
7
  it "produces the correct failure message when used in the positive" do
7
8
  as_both_colored_and_uncolored do |color_enabled|
8
9
  snippet = <<~TEST.strip
9
10
  expected = ["Marty", "Einie"]
10
- actual = ["Marty", "Jennifer", "Doc"]
11
+ actual = ["Marty", "Jennifer", "Doc"]
11
12
  expect(actual).to include(*expected)
12
13
  TEST
13
- program = make_plain_test_program(
14
- snippet,
15
- color_enabled: color_enabled,
16
- )
14
+ program =
15
+ make_plain_test_program(snippet, color_enabled: color_enabled)
17
16
 
18
- expected_output = build_expected_output(
19
- color_enabled: color_enabled,
20
- snippet: %|expect(actual).to include(*expected)|,
21
- expectation: proc {
22
- line do
23
- plain %|Expected |
24
- actual %|["Marty", "Jennifer", "Doc"]|
25
- plain %| to include |
26
- expected %|"Einie"|
27
- plain %|.|
28
- end
29
- },
30
- diff: proc {
31
- plain_line %| [|
32
- plain_line %| "Marty",|
33
- plain_line %| "Jennifer",|
34
- # plain_line %| "Doc",| # FIXME
35
- plain_line %| "Doc"|
36
- expected_line %|- "Einie"|
37
- plain_line %| ]|
38
- },
39
- )
17
+ expected_output =
18
+ build_expected_output(
19
+ color_enabled: color_enabled,
20
+ snippet: "expect(actual).to include(*expected)",
21
+ expectation:
22
+ proc do
23
+ line do
24
+ plain "Expected "
25
+ actual %|["Marty", "Jennifer", "Doc"]|
26
+ plain " to include "
27
+ expected %|"Einie"|
28
+ plain "."
29
+ end
30
+ end,
31
+ diff:
32
+ proc do
33
+ plain_line " ["
34
+ plain_line %| "Marty",|
35
+ plain_line %| "Jennifer",|
36
+ # plain_line %| "Doc",| # FIXME
37
+ plain_line %| "Doc"|
38
+ expected_line %|- "Einie"|
39
+ plain_line " ]"
40
+ end
41
+ )
40
42
 
41
- expect(program).
42
- to produce_output_when_run(expected_output).
43
- in_color(color_enabled)
43
+ expect(program).to produce_output_when_run(expected_output).in_color(
44
+ color_enabled
45
+ )
44
46
  end
45
47
  end
46
48
 
@@ -50,28 +52,28 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
50
52
  values = ["Marty", "Einie"]
51
53
  expect(values).not_to include(*values)
52
54
  TEST
53
- program = make_plain_test_program(
54
- snippet,
55
- color_enabled: color_enabled,
56
- )
55
+ program =
56
+ make_plain_test_program(snippet, color_enabled: color_enabled)
57
57
 
58
- expected_output = build_expected_output(
59
- color_enabled: color_enabled,
60
- snippet: %|expect(values).not_to include(*values)|,
61
- expectation: proc {
62
- line do
63
- plain %|Expected |
64
- actual %|["Marty", "Einie"]|
65
- plain %| not to include |
66
- expected %|"Marty" and "Einie"|
67
- plain %|.|
68
- end
69
- },
70
- )
58
+ expected_output =
59
+ build_expected_output(
60
+ color_enabled: color_enabled,
61
+ snippet: "expect(values).not_to include(*values)",
62
+ expectation:
63
+ proc do
64
+ line do
65
+ plain "Expected "
66
+ actual %|["Marty", "Einie"]|
67
+ plain " not to include "
68
+ expected %|"Marty" and "Einie"|
69
+ plain "."
70
+ end
71
+ end
72
+ )
71
73
 
72
- expect(program).
73
- to produce_output_when_run(expected_output).
74
- in_color(color_enabled)
74
+ expect(program).to produce_output_when_run(expected_output).in_color(
75
+ color_enabled
76
+ )
75
77
  end
76
78
  end
77
79
  end
@@ -88,7 +90,7 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
88
90
  "George McFly",
89
91
  "Lorraine McFly"
90
92
  ]
91
- actual = [
93
+ actual = [
92
94
  "Marty McFly",
93
95
  "Doc Brown",
94
96
  "Einie",
@@ -96,41 +98,42 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
96
98
  ]
97
99
  expect(actual).to include(*expected)
98
100
  TEST
99
- program = make_plain_test_program(
100
- snippet,
101
- color_enabled: color_enabled,
102
- )
101
+ program =
102
+ make_plain_test_program(snippet, color_enabled: color_enabled)
103
103
 
104
- expected_output = build_expected_output(
105
- color_enabled: color_enabled,
106
- snippet: %|expect(actual).to include(*expected)|,
107
- expectation: proc {
108
- line do
109
- plain %| Expected |
110
- actual %|["Marty McFly", "Doc Brown", "Einie", "Lorraine McFly"]|
111
- end
112
-
113
- line do
114
- plain %|to include |
115
- expected %|"Biff Tannen" and "George McFly"|
116
- end
117
- },
118
- diff: proc {
119
- plain_line %| [|
120
- plain_line %| "Marty McFly",|
121
- plain_line %| "Doc Brown",|
122
- plain_line %| "Einie",|
123
- # plain_line %| "Lorraine McFly",| # FIXME
124
- plain_line %| "Lorraine McFly"|
125
- expected_line %|- "Biff Tannen",|
126
- expected_line %|- "George McFly"|
127
- plain_line %| ]|
128
- },
129
- )
104
+ expected_output =
105
+ build_expected_output(
106
+ color_enabled: color_enabled,
107
+ snippet: "expect(actual).to include(*expected)",
108
+ expectation:
109
+ proc do
110
+ line do
111
+ plain " Expected "
112
+ actual %|["Marty McFly", "Doc Brown", "Einie", "Lorraine McFly"]|
113
+ end
114
+
115
+ line do
116
+ plain "to include "
117
+ expected %|"Biff Tannen" and "George McFly"|
118
+ end
119
+ end,
120
+ diff:
121
+ proc do
122
+ plain_line " ["
123
+ plain_line %| "Marty McFly",|
124
+ plain_line %| "Doc Brown",|
125
+ plain_line %| "Einie",|
126
+ # plain_line %| "Lorraine McFly",| # FIXME
127
+ plain_line %| "Lorraine McFly"|
128
+ expected_line %|- "Biff Tannen",|
129
+ expected_line %|- "George McFly"|
130
+ plain_line " ]"
131
+ end
132
+ )
130
133
 
131
- expect(program).
132
- to produce_output_when_run(expected_output).
133
- in_color(color_enabled)
134
+ expect(program).to produce_output_when_run(expected_output).in_color(
135
+ color_enabled
136
+ )
134
137
  end
135
138
  end
136
139
 
@@ -143,7 +146,7 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
143
146
  "Einie",
144
147
  "Lorraine McFly"
145
148
  ]
146
- actual = [
149
+ actual = [
147
150
  "Marty McFly",
148
151
  "Doc Brown",
149
152
  "Einie",
@@ -153,31 +156,31 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
153
156
  ]
154
157
  expect(actual).not_to include(*expected)
155
158
  TEST
156
- program = make_plain_test_program(
157
- snippet,
158
- color_enabled: color_enabled,
159
- )
159
+ program =
160
+ make_plain_test_program(snippet, color_enabled: color_enabled)
160
161
 
161
- expected_output = build_expected_output(
162
- color_enabled: color_enabled,
163
- snippet: %|expect(actual).not_to include(*expected)|,
164
- newline_before_expectation: true,
165
- expectation: proc {
166
- line do
167
- plain %| Expected |
168
- actual %|["Marty McFly", "Doc Brown", "Einie", "Biff Tannen", "George McFly", "Lorraine McFly"]|
169
- end
170
-
171
- line do
172
- plain %|not to include |
173
- expected %|"Marty McFly", "Doc Brown", "Einie", and "Lorraine McFly"|
174
- end
175
- },
176
- )
162
+ expected_output =
163
+ build_expected_output(
164
+ color_enabled: color_enabled,
165
+ snippet: "expect(actual).not_to include(*expected)",
166
+ newline_before_expectation: true,
167
+ expectation:
168
+ proc do
169
+ line do
170
+ plain " Expected "
171
+ actual %|["Marty McFly", "Doc Brown", "Einie", "Biff Tannen", "George McFly", "Lorraine McFly"]|
172
+ end
173
+
174
+ line do
175
+ plain "not to include "
176
+ expected %|"Marty McFly", "Doc Brown", "Einie", and "Lorraine McFly"|
177
+ end
178
+ end
179
+ )
177
180
 
178
- expect(program).
179
- to produce_output_when_run(expected_output).
180
- in_color(color_enabled)
181
+ expect(program).to produce_output_when_run(expected_output).in_color(
182
+ color_enabled
183
+ )
181
184
  end
182
185
  end
183
186
  end
@@ -189,41 +192,42 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
189
192
  as_both_colored_and_uncolored do |color_enabled|
190
193
  snippet = <<~TEST.strip
191
194
  expected = { city: "Hill Valley", state: "CA" }
192
- actual = { city: "Burbank", zip: "90210" }
195
+ actual = { city: "Burbank", zip: "90210" }
193
196
  expect(actual).to include(expected)
194
197
  TEST
195
- program = make_plain_test_program(
196
- snippet,
197
- color_enabled: color_enabled,
198
- )
198
+ program =
199
+ make_plain_test_program(snippet, color_enabled: color_enabled)
199
200
 
200
- expected_output = build_expected_output(
201
- color_enabled: color_enabled,
202
- snippet: %|expect(actual).to include(expected)|,
203
- expectation: proc {
204
- line do
205
- plain %|Expected |
206
- actual %|{ city: "Burbank", zip: "90210" }|
207
- plain %| to include |
208
- expected %|(city: "Hill Valley", state: "CA")|
209
- plain %|.|
210
- end
211
- },
212
- diff: proc {
213
- plain_line %| {|
214
- expected_line %|- city: "Hill Valley",|
215
- actual_line %|+ city: "Burbank",|
216
- # FIXME
217
- # expected_line %|- state: "CA",|
218
- expected_line %|- state: "CA"|
219
- plain_line %| zip: "90210"|
220
- plain_line %| }|
221
- },
222
- )
201
+ expected_output =
202
+ build_expected_output(
203
+ color_enabled: color_enabled,
204
+ snippet: "expect(actual).to include(expected)",
205
+ expectation:
206
+ proc do
207
+ line do
208
+ plain "Expected "
209
+ actual %|{ city: "Burbank", zip: "90210" }|
210
+ plain " to include "
211
+ expected %|(city: "Hill Valley", state: "CA")|
212
+ plain "."
213
+ end
214
+ end,
215
+ diff:
216
+ proc do
217
+ plain_line " {"
218
+ expected_line %|- city: "Hill Valley",|
219
+ actual_line %|+ city: "Burbank",|
220
+ # FIXME
221
+ # expected_line %|- state: "CA",|
222
+ expected_line %|- state: "CA"|
223
+ plain_line %| zip: "90210"|
224
+ plain_line " }"
225
+ end
226
+ )
223
227
 
224
- expect(program).
225
- to produce_output_when_run(expected_output).
226
- in_color(color_enabled)
228
+ expect(program).to produce_output_when_run(expected_output).in_color(
229
+ color_enabled
230
+ )
227
231
  end
228
232
  end
229
233
 
@@ -231,31 +235,72 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
231
235
  as_both_colored_and_uncolored do |color_enabled|
232
236
  snippet = <<~TEST.strip
233
237
  expected = { city: "Burbank" }
234
- actual = { city: "Burbank", zip: "90210" }
238
+ actual = { city: "Burbank", zip: "90210" }
235
239
  expect(actual).not_to include(expected)
236
240
  TEST
237
- program = make_plain_test_program(
238
- snippet,
239
- color_enabled: color_enabled,
240
- )
241
+ program =
242
+ make_plain_test_program(snippet, color_enabled: color_enabled)
243
+
244
+ expected_output =
245
+ build_expected_output(
246
+ color_enabled: color_enabled,
247
+ snippet: "expect(actual).not_to include(expected)",
248
+ expectation:
249
+ proc do
250
+ line do
251
+ plain "Expected "
252
+ actual %|{ city: "Burbank", zip: "90210" }|
253
+ plain " not to include "
254
+ expected %|(city: "Burbank")|
255
+ plain "."
256
+ end
257
+ end
258
+ )
241
259
 
242
- expected_output = build_expected_output(
243
- color_enabled: color_enabled,
244
- snippet: %|expect(actual).not_to include(expected)|,
245
- expectation: proc {
246
- line do
247
- plain %|Expected |
248
- actual %|{ city: "Burbank", zip: "90210" }|
249
- plain %| not to include |
250
- expected %|(city: "Burbank")|
251
- plain %|.|
252
- end
253
- },
260
+ expect(program).to produce_output_when_run(expected_output).in_color(
261
+ color_enabled
254
262
  )
263
+ end
264
+ end
265
+
266
+ it "produces the correct failure message when fuzzy matching" do
267
+ as_both_colored_and_uncolored do |color_enabled|
268
+ snippet = <<~TEST.strip
269
+ expected = { number: a_kind_of(Numeric), city: /burb/i, state: "CA" }
270
+ actual = { number: 42, city: "Burbank", zip: "90210" }
271
+ expect(actual).to include(expected)
272
+ TEST
273
+ program =
274
+ make_plain_test_program(snippet, color_enabled: color_enabled)
255
275
 
256
- expect(program).
257
- to produce_output_when_run(expected_output).
258
- in_color(color_enabled)
276
+ expected_output =
277
+ build_expected_output(
278
+ color_enabled: color_enabled,
279
+ snippet: "expect(actual).to include(expected)",
280
+ expectation:
281
+ proc do
282
+ line do
283
+ plain "Expected "
284
+ actual %|{ number: 42, city: "Burbank", zip: "90210" }|
285
+ plain " to include "
286
+ expected %|(state: "CA")|
287
+ plain "."
288
+ end
289
+ end,
290
+ diff:
291
+ proc do
292
+ plain_line " {"
293
+ plain_line " number: 42,"
294
+ plain_line %| city: "Burbank",|
295
+ plain_line %| zip: "90210"|
296
+ expected_line %|- state: "CA"|
297
+ plain_line " }"
298
+ end
299
+ )
300
+
301
+ expect(program).to produce_output_when_run(expected_output).in_color(
302
+ color_enabled
303
+ )
259
304
  end
260
305
  end
261
306
  end
@@ -268,46 +313,47 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
268
313
  city: "Hill Valley",
269
314
  zip: "90382"
270
315
  }
271
- actual = {
316
+ actual = {
272
317
  city: "Burbank",
273
318
  state: "CA",
274
319
  zip: "90210"
275
320
  }
276
321
  expect(actual).to include(expected)
277
322
  TEST
278
- program = make_plain_test_program(
279
- snippet,
280
- color_enabled: color_enabled,
281
- )
323
+ program =
324
+ make_plain_test_program(snippet, color_enabled: color_enabled)
282
325
 
283
- expected_output = build_expected_output(
284
- color_enabled: color_enabled,
285
- snippet: %|expect(actual).to include(expected)|,
286
- expectation: proc {
287
- line do
288
- plain %| Expected |
289
- actual %|{ city: "Burbank", state: "CA", zip: "90210" }|
290
- end
291
-
292
- line do
293
- plain %|to include |
294
- expected %|(city: "Hill Valley", zip: "90382")|
295
- end
296
- },
297
- diff: proc {
298
- plain_line %| {|
299
- expected_line %|- city: "Hill Valley",|
300
- actual_line %|+ city: "Burbank",|
301
- plain_line %| state: "CA",|
302
- expected_line %|- zip: "90382"|
303
- actual_line %|+ zip: "90210"|
304
- plain_line %| }|
305
- },
306
- )
326
+ expected_output =
327
+ build_expected_output(
328
+ color_enabled: color_enabled,
329
+ snippet: "expect(actual).to include(expected)",
330
+ expectation:
331
+ proc do
332
+ line do
333
+ plain " Expected "
334
+ actual %|{ city: "Burbank", state: "CA", zip: "90210" }|
335
+ end
307
336
 
308
- expect(program).
309
- to produce_output_when_run(expected_output).
310
- in_color(color_enabled)
337
+ line do
338
+ plain "to include "
339
+ expected %|(city: "Hill Valley", zip: "90382")|
340
+ end
341
+ end,
342
+ diff:
343
+ proc do
344
+ plain_line " {"
345
+ expected_line %|- city: "Hill Valley",|
346
+ actual_line %|+ city: "Burbank",|
347
+ plain_line %| state: "CA",|
348
+ expected_line %|- zip: "90382"|
349
+ actual_line %|+ zip: "90210"|
350
+ plain_line " }"
351
+ end
352
+ )
353
+
354
+ expect(program).to produce_output_when_run(expected_output).in_color(
355
+ color_enabled
356
+ )
311
357
  end
312
358
  end
313
359
 
@@ -315,34 +361,90 @@ RSpec.describe "Integration with RSpec's #include matcher", type: :integration d
315
361
  as_both_colored_and_uncolored do |color_enabled|
316
362
  snippet = <<~TEST.strip
317
363
  expected = { city: "Hill Valley", state: "CA" }
318
- actual = { city: "Hill Valley", state: "CA", zip: "90210" }
364
+ actual = { city: "Hill Valley", state: "CA", zip: "90210" }
319
365
  expect(actual).not_to include(expected)
320
366
  TEST
321
- program = make_plain_test_program(
322
- snippet,
323
- color_enabled: color_enabled,
324
- )
367
+ program =
368
+ make_plain_test_program(snippet, color_enabled: color_enabled)
325
369
 
326
- expected_output = build_expected_output(
327
- color_enabled: color_enabled,
328
- snippet: %|expect(actual).not_to include(expected)|,
329
- newline_before_expectation: true,
330
- expectation: proc {
331
- line do
332
- plain %| Expected |
333
- actual %|{ city: "Hill Valley", state: "CA", zip: "90210" }|
334
- end
335
-
336
- line do
337
- plain %|not to include |
338
- expected %|(city: "Hill Valley", state: "CA")|
339
- end
340
- },
370
+ expected_output =
371
+ build_expected_output(
372
+ color_enabled: color_enabled,
373
+ snippet: "expect(actual).not_to include(expected)",
374
+ newline_before_expectation: true,
375
+ expectation:
376
+ proc do
377
+ line do
378
+ plain " Expected "
379
+ actual %|{ city: "Hill Valley", state: "CA", zip: "90210" }|
380
+ end
381
+
382
+ line do
383
+ plain "not to include "
384
+ expected %|(city: "Hill Valley", state: "CA")|
385
+ end
386
+ end
387
+ )
388
+
389
+ expect(program).to produce_output_when_run(expected_output).in_color(
390
+ color_enabled
341
391
  )
392
+ end
393
+ end
394
+
395
+ it "produces the correct failure message when fuzzy matching" do
396
+ as_both_colored_and_uncolored do |color_enabled|
397
+ snippet = <<~TEST.strip
398
+ expected = {
399
+ number: a_kind_of(Numeric),
400
+ street: "Yoshie Circles",
401
+ city: /burb/i,
402
+ zip: "90382"
403
+ }
404
+ actual = {
405
+ number: 42,
406
+ street: "Yoshie Circles",
407
+ city: "Burbank",
408
+ state: "CA",
409
+ zip: "90210"
410
+ }
411
+ expect(actual).to include(expected)
412
+ TEST
413
+ program =
414
+ make_plain_test_program(snippet, color_enabled: color_enabled)
342
415
 
343
- expect(program).
344
- to produce_output_when_run(expected_output).
345
- in_color(color_enabled)
416
+ expected_output =
417
+ build_expected_output(
418
+ color_enabled: color_enabled,
419
+ snippet: "expect(actual).to include(expected)",
420
+ expectation:
421
+ proc do
422
+ line do
423
+ plain " Expected "
424
+ actual %|{ number: 42, street: "Yoshie Circles", city: "Burbank", state: "CA", zip: "90210" }|
425
+ end
426
+
427
+ line do
428
+ plain "to include "
429
+ expected %|(zip: "90382")|
430
+ end
431
+ end,
432
+ diff:
433
+ proc do
434
+ plain_line " {"
435
+ plain_line " number: 42,"
436
+ plain_line %| street: "Yoshie Circles",|
437
+ plain_line %| city: "Burbank",|
438
+ plain_line %| state: "CA",|
439
+ expected_line %|- zip: "90382"|
440
+ actual_line %|+ zip: "90210"|
441
+ plain_line " }"
442
+ end
443
+ )
444
+
445
+ expect(program).to produce_output_when_run(expected_output).in_color(
446
+ color_enabled
447
+ )
346
448
  end
347
449
  end
348
450
  end