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
@@ -4,51 +4,55 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
4
4
  context "when comparing two different integers" do
5
5
  it "produces the correct failure message when used in the positive" do
6
6
  as_both_colored_and_uncolored do |color_enabled|
7
- snippet = %|expect(1).to eq(42)|
7
+ snippet = "expect(1).to eq(42)"
8
8
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
9
9
 
10
- expected_output = build_expected_output(
11
- color_enabled: color_enabled,
12
- snippet: snippet,
13
- expectation: proc {
14
- line do
15
- plain %|Expected |
16
- actual %|1|
17
- plain %| to eq |
18
- expected %|42|
19
- plain %|.|
20
- end
21
- },
22
- )
10
+ expected_output =
11
+ build_expected_output(
12
+ color_enabled: color_enabled,
13
+ snippet: snippet,
14
+ expectation:
15
+ proc do
16
+ line do
17
+ plain "Expected "
18
+ actual "1"
19
+ plain " to eq "
20
+ expected "42"
21
+ plain "."
22
+ end
23
+ end
24
+ )
23
25
 
24
- expect(program).
25
- to produce_output_when_run(expected_output).
26
- in_color(color_enabled)
26
+ expect(program).to produce_output_when_run(expected_output).in_color(
27
+ color_enabled
28
+ )
27
29
  end
28
30
  end
29
31
 
30
32
  it "produces the correct failure message when used in the negative" do
31
33
  as_both_colored_and_uncolored do |color_enabled|
32
- snippet = %|expect(42).not_to eq(42)|
34
+ snippet = "expect(42).not_to eq(42)"
33
35
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
34
36
 
35
- expected_output = build_expected_output(
36
- color_enabled: color_enabled,
37
- snippet: snippet,
38
- expectation: proc {
39
- line do
40
- plain %|Expected |
41
- actual %|42|
42
- plain %| not to eq |
43
- expected %|42|
44
- plain %|.|
45
- end
46
- },
47
- )
37
+ expected_output =
38
+ build_expected_output(
39
+ color_enabled: color_enabled,
40
+ snippet: snippet,
41
+ expectation:
42
+ proc do
43
+ line do
44
+ plain "Expected "
45
+ actual "42"
46
+ plain " not to eq "
47
+ expected "42"
48
+ plain "."
49
+ end
50
+ end
51
+ )
48
52
 
49
- expect(program).
50
- to produce_output_when_run(expected_output).
51
- in_color(color_enabled)
53
+ expect(program).to produce_output_when_run(expected_output).in_color(
54
+ color_enabled
55
+ )
52
56
  end
53
57
  end
54
58
  end
@@ -56,57 +60,55 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
56
60
  context "when comparing two different symbols" do
57
61
  it "produces the correct failure message when used in the positive" do
58
62
  as_both_colored_and_uncolored do |color_enabled|
59
- snippet = %|expect(:bar).to eq(:foo)|
60
- program = make_plain_test_program(
61
- snippet,
62
- color_enabled: color_enabled,
63
- )
63
+ snippet = "expect(:bar).to eq(:foo)"
64
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
64
65
 
65
- expected_output = build_expected_output(
66
- color_enabled: color_enabled,
67
- snippet: snippet,
68
- expectation: proc {
69
- line do
70
- plain %|Expected |
71
- actual %|:bar|
72
- plain %| to eq |
73
- expected %|:foo|
74
- plain %|.|
75
- end
76
- },
77
- )
66
+ expected_output =
67
+ build_expected_output(
68
+ color_enabled: color_enabled,
69
+ snippet: snippet,
70
+ expectation:
71
+ proc do
72
+ line do
73
+ plain "Expected "
74
+ actual ":bar"
75
+ plain " to eq "
76
+ expected ":foo"
77
+ plain "."
78
+ end
79
+ end
80
+ )
78
81
 
79
- expect(program).
80
- to produce_output_when_run(expected_output).
81
- in_color(color_enabled)
82
+ expect(program).to produce_output_when_run(expected_output).in_color(
83
+ color_enabled
84
+ )
82
85
  end
83
86
  end
84
87
 
85
88
  it "produces the correct failure message when used in the negative" do
86
89
  as_both_colored_and_uncolored do |color_enabled|
87
- snippet = %|expect(:foo).not_to eq(:foo)|
88
- program = make_plain_test_program(
89
- snippet,
90
- color_enabled: color_enabled,
91
- )
90
+ snippet = "expect(:foo).not_to eq(:foo)"
91
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
92
92
 
93
- expected_output = build_expected_output(
94
- color_enabled: color_enabled,
95
- snippet: snippet,
96
- expectation: proc {
97
- line do
98
- plain %|Expected |
99
- actual %|:foo|
100
- plain %| not to eq |
101
- expected %|:foo|
102
- plain %|.|
103
- end
104
- },
105
- )
93
+ expected_output =
94
+ build_expected_output(
95
+ color_enabled: color_enabled,
96
+ snippet: snippet,
97
+ expectation:
98
+ proc do
99
+ line do
100
+ plain "Expected "
101
+ actual ":foo"
102
+ plain " not to eq "
103
+ expected ":foo"
104
+ plain "."
105
+ end
106
+ end
107
+ )
106
108
 
107
- expect(program).
108
- to produce_output_when_run(expected_output).
109
- in_color(color_enabled)
109
+ expect(program).to produce_output_when_run(expected_output).in_color(
110
+ color_enabled
111
+ )
110
112
  end
111
113
  end
112
114
  end
@@ -115,56 +117,54 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
115
117
  it "produces the correct failure message when used in the positive" do
116
118
  as_both_colored_and_uncolored do |color_enabled|
117
119
  snippet = %|expect("Jennifer").to eq("Marty")|
118
- program = make_plain_test_program(
119
- snippet,
120
- color_enabled: color_enabled,
121
- )
120
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
122
121
 
123
- expected_output = build_expected_output(
124
- color_enabled: color_enabled,
125
- snippet: %|expect("Jennifer").to eq("Marty")|,
126
- expectation: proc {
127
- line do
128
- plain %|Expected |
129
- actual %|"Jennifer"|
130
- plain %| to eq |
131
- expected %|"Marty"|
132
- plain %|.|
133
- end
134
- },
135
- )
122
+ expected_output =
123
+ build_expected_output(
124
+ color_enabled: color_enabled,
125
+ snippet: %|expect("Jennifer").to eq("Marty")|,
126
+ expectation:
127
+ proc do
128
+ line do
129
+ plain "Expected "
130
+ actual %|"Jennifer"|
131
+ plain " to eq "
132
+ expected %|"Marty"|
133
+ plain "."
134
+ end
135
+ end
136
+ )
136
137
 
137
- expect(program).
138
- to produce_output_when_run(expected_output).
139
- in_color(color_enabled)
138
+ expect(program).to produce_output_when_run(expected_output).in_color(
139
+ color_enabled
140
+ )
140
141
  end
141
142
  end
142
143
 
143
144
  it "produces the correct failure message when used in the negative" do
144
145
  as_both_colored_and_uncolored do |color_enabled|
145
146
  snippet = %|expect("Jennifer").not_to eq("Jennifer")|
146
- program = make_plain_test_program(
147
- snippet,
148
- color_enabled: color_enabled,
149
- )
147
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
150
148
 
151
- expected_output = build_expected_output(
152
- color_enabled: color_enabled,
153
- snippet: %|expect("Jennifer").not_to eq("Jennifer")|,
154
- expectation: proc {
155
- line do
156
- plain %|Expected |
157
- actual %|"Jennifer"|
158
- plain %| not to eq |
159
- expected %|"Jennifer"|
160
- plain %|.|
161
- end
162
- },
163
- )
149
+ expected_output =
150
+ build_expected_output(
151
+ color_enabled: color_enabled,
152
+ snippet: %|expect("Jennifer").not_to eq("Jennifer")|,
153
+ expectation:
154
+ proc do
155
+ line do
156
+ plain "Expected "
157
+ actual %|"Jennifer"|
158
+ plain " not to eq "
159
+ expected %|"Jennifer"|
160
+ plain "."
161
+ end
162
+ end
163
+ )
164
164
 
165
- expect(program).
166
- to produce_output_when_run(expected_output).
167
- in_color(color_enabled)
165
+ expect(program).to produce_output_when_run(expected_output).in_color(
166
+ color_enabled
167
+ )
168
168
  end
169
169
  end
170
170
  end
@@ -174,47 +174,47 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
174
174
  as_both_colored_and_uncolored do |color_enabled|
175
175
  snippet = <<~RUBY
176
176
  expected = Time.utc(2011, 12, 13, 14, 15, 16)
177
- actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
177
+ actual = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
178
178
  expect(expected).to eq(actual)
179
179
  RUBY
180
- program = make_plain_test_program(
181
- snippet,
182
- color_enabled: color_enabled,
183
- )
180
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
184
181
 
185
- expected_output = build_expected_output(
186
- color_enabled: color_enabled,
187
- snippet: %|expect(expected).to eq(actual)|,
188
- expectation: proc {
189
- line do
190
- plain %|Expected |
191
- actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
192
- end
193
-
194
- line do
195
- plain %| to eq |
196
- expected %|#<Time 2011-12-13 14:15:16+(1/2) +00:00 (UTC)>|
197
- end
198
- },
199
- diff: proc {
200
- plain_line " #<Time {"
201
- plain_line " year: 2011,"
202
- plain_line " month: 12,"
203
- plain_line " day: 13,"
204
- plain_line " hour: 14,"
205
- plain_line " min: 15,"
206
- plain_line " sec: 16,"
207
- expected_line "- subsec: (1/2),"
208
- actual_line "+ subsec: 0,"
209
- plain_line " zone: \"UTC\","
210
- plain_line " utc_offset: 0"
211
- plain_line " }>"
212
- },
213
- )
182
+ expected_output =
183
+ build_expected_output(
184
+ color_enabled: color_enabled,
185
+ snippet: "expect(expected).to eq(actual)",
186
+ expectation:
187
+ proc do
188
+ line do
189
+ plain "Expected "
190
+ actual "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
191
+ end
192
+
193
+ line do
194
+ plain " to eq "
195
+ expected "#<Time 2011-12-13 14:15:16+(1/2) +00:00 (UTC)>"
196
+ end
197
+ end,
198
+ diff:
199
+ proc do
200
+ plain_line " #<Time {"
201
+ plain_line " year: 2011,"
202
+ plain_line " month: 12,"
203
+ plain_line " day: 13,"
204
+ plain_line " hour: 14,"
205
+ plain_line " min: 15,"
206
+ plain_line " sec: 16,"
207
+ expected_line "- subsec: (1/2),"
208
+ actual_line "+ subsec: 0,"
209
+ plain_line " zone: \"UTC\","
210
+ plain_line " utc_offset: 0"
211
+ plain_line " }>"
212
+ end
213
+ )
214
214
 
215
- expect(program).
216
- to produce_output_when_run(expected_output).
217
- in_color(color_enabled)
215
+ expect(program).to produce_output_when_run(expected_output).in_color(
216
+ color_enabled
217
+ )
218
218
  end
219
219
  end
220
220
 
@@ -224,31 +224,30 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
224
224
  time = Time.utc(2011, 12, 13, 14, 15, 16)
225
225
  expect(time).not_to eq(time)
226
226
  RUBY
227
- program = make_plain_test_program(
228
- snippet,
229
- color_enabled: color_enabled,
230
- )
227
+ program = make_plain_test_program(snippet, color_enabled: color_enabled)
231
228
 
232
- expected_output = build_expected_output(
233
- color_enabled: color_enabled,
234
- snippet: %|expect(time).not_to eq(time)|,
235
- newline_before_expectation: true,
236
- expectation: proc {
237
- line do
238
- plain %| Expected |
239
- actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
240
- end
241
-
242
- line do
243
- plain %|not to eq |
244
- expected %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
245
- end
246
- },
247
- )
229
+ expected_output =
230
+ build_expected_output(
231
+ color_enabled: color_enabled,
232
+ snippet: "expect(time).not_to eq(time)",
233
+ newline_before_expectation: true,
234
+ expectation:
235
+ proc do
236
+ line do
237
+ plain " Expected "
238
+ actual "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
239
+ end
240
+
241
+ line do
242
+ plain "not to eq "
243
+ expected "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
244
+ end
245
+ end
246
+ )
248
247
 
249
- expect(program).
250
- to produce_output_when_run(expected_output).
251
- in_color(color_enabled)
248
+ expect(program).to produce_output_when_run(expected_output).in_color(
249
+ color_enabled
250
+ )
252
251
  end
253
252
  end
254
253
  end
@@ -258,33 +257,36 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
258
257
  as_both_colored_and_uncolored do |color_enabled|
259
258
  snippet = <<~TEST.strip
260
259
  expected = "Something entirely different"
261
- actual = "This is a line\\nAnd that's another line\\n"
260
+ actual = "This is a line\\nAnd that's another line\\n"
262
261
  expect(actual).to eq(expected)
263
262
  TEST
264
263
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
265
264
 
266
- expected_output = build_expected_output(
267
- color_enabled: color_enabled,
268
- snippet: %|expect(actual).to eq(expected)|,
269
- expectation: proc {
270
- line do
271
- plain %|Expected |
272
- actual %|"This is a line\\nAnd that's another line\\n"|
273
- plain %| to eq |
274
- expected %|"Something entirely different"|
275
- plain %|.|
276
- end
277
- },
278
- diff: proc {
279
- expected_line %|- Something entirely different|
280
- actual_line %|+ This is a line\\n|
281
- actual_line %|+ And that's another line\\n|
282
- },
283
- )
265
+ expected_output =
266
+ build_expected_output(
267
+ color_enabled: color_enabled,
268
+ snippet: "expect(actual).to eq(expected)",
269
+ expectation:
270
+ proc do
271
+ line do
272
+ plain "Expected "
273
+ actual %|"This is a line\\nAnd that's another line\\n"|
274
+ plain " to eq "
275
+ expected %|"Something entirely different"|
276
+ plain "."
277
+ end
278
+ end,
279
+ diff:
280
+ proc do
281
+ expected_line "- Something entirely different"
282
+ actual_line %|+ This is a line\\n|
283
+ actual_line %|+ And that's another line\\n|
284
+ end
285
+ )
284
286
 
285
- expect(program).
286
- to produce_output_when_run(expected_output).
287
- in_color(color_enabled)
287
+ expect(program).to produce_output_when_run(expected_output).in_color(
288
+ color_enabled
289
+ )
288
290
  end
289
291
  end
290
292
  end
@@ -294,33 +296,36 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
294
296
  as_both_colored_and_uncolored do |color_enabled|
295
297
  snippet = <<~TEST.strip
296
298
  expected = "This is a line\\nAnd that's another line\\n"
297
- actual = "Something entirely different"
299
+ actual = "Something entirely different"
298
300
  expect(actual).to eq(expected)
299
301
  TEST
300
302
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
301
303
 
302
- expected_output = build_expected_output(
303
- color_enabled: color_enabled,
304
- snippet: %|expect(actual).to eq(expected)|,
305
- expectation: proc {
306
- line do
307
- plain %|Expected |
308
- actual %|"Something entirely different"|
309
- plain %| to eq |
310
- expected %|"This is a line\\nAnd that's another line\\n"|
311
- plain %|.|
312
- end
313
- },
314
- diff: proc {
315
- expected_line %|- This is a line\\n|
316
- expected_line %|- And that's another line\\n|
317
- actual_line %|+ Something entirely different|
318
- },
319
- )
304
+ expected_output =
305
+ build_expected_output(
306
+ color_enabled: color_enabled,
307
+ snippet: "expect(actual).to eq(expected)",
308
+ expectation:
309
+ proc do
310
+ line do
311
+ plain "Expected "
312
+ actual %|"Something entirely different"|
313
+ plain " to eq "
314
+ expected %|"This is a line\\nAnd that's another line\\n"|
315
+ plain "."
316
+ end
317
+ end,
318
+ diff:
319
+ proc do
320
+ expected_line %|- This is a line\\n|
321
+ expected_line %|- And that's another line\\n|
322
+ actual_line "+ Something entirely different"
323
+ end
324
+ )
320
325
 
321
- expect(program).
322
- to produce_output_when_run(expected_output).
323
- in_color(color_enabled)
326
+ expect(program).to produce_output_when_run(expected_output).in_color(
327
+ color_enabled
328
+ )
324
329
  end
325
330
  end
326
331
  end
@@ -330,36 +335,39 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
330
335
  as_both_colored_and_uncolored do |color_enabled|
331
336
  snippet = <<~TEST.strip
332
337
  expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
333
- actual = "This is a line\\nSomething completely different\\nAnd there's a line too\\n"
338
+ actual = "This is a line\\nSomething completely different\\nAnd there's a line too\\n"
334
339
  expect(actual).to eq(expected)
335
340
  TEST
336
341
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
337
342
 
338
- expected_output = build_expected_output(
339
- color_enabled: color_enabled,
340
- snippet: %|expect(actual).to eq(expected)|,
341
- expectation: proc {
342
- line do
343
- plain %|Expected |
344
- actual %|"This is a line\\nSomething completely different\\nAnd there's a line too\\n"|
345
- end
346
-
347
- line do
348
- plain %| to eq |
349
- expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
350
- end
351
- },
352
- diff: proc {
353
- plain_line %| This is a line\\n|
354
- expected_line %|- And that's a line\\n|
355
- actual_line %|+ Something completely different\\n|
356
- plain_line %| And there's a line too\\n|
357
- },
358
- )
343
+ expected_output =
344
+ build_expected_output(
345
+ color_enabled: color_enabled,
346
+ snippet: "expect(actual).to eq(expected)",
347
+ expectation:
348
+ proc do
349
+ line do
350
+ plain "Expected "
351
+ actual %|"This is a line\\nSomething completely different\\nAnd there's a line too\\n"|
352
+ end
353
+
354
+ line do
355
+ plain " to eq "
356
+ expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
357
+ end
358
+ end,
359
+ diff:
360
+ proc do
361
+ plain_line %| This is a line\\n|
362
+ expected_line %|- And that's a line\\n|
363
+ actual_line %|+ Something completely different\\n|
364
+ plain_line %| And there's a line too\\n|
365
+ end
366
+ )
359
367
 
360
- expect(program).
361
- to produce_output_when_run(expected_output).
362
- in_color(color_enabled)
368
+ expect(program).to produce_output_when_run(expected_output).in_color(
369
+ color_enabled
370
+ )
363
371
  end
364
372
  end
365
373
 
@@ -371,26 +379,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
371
379
  TEST
372
380
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
373
381
 
374
- expected_output = build_expected_output(
375
- color_enabled: color_enabled,
376
- snippet: %|expect(string).not_to eq(string)|,
377
- newline_before_expectation: true,
378
- expectation: proc {
379
- line do
380
- plain %| Expected |
381
- actual %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
382
- end
383
-
384
- line do
385
- plain %|not to eq |
386
- expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
387
- end
388
- },
389
- )
382
+ expected_output =
383
+ build_expected_output(
384
+ color_enabled: color_enabled,
385
+ snippet: "expect(string).not_to eq(string)",
386
+ newline_before_expectation: true,
387
+ expectation:
388
+ proc do
389
+ line do
390
+ plain " Expected "
391
+ actual %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
392
+ end
393
+
394
+ line do
395
+ plain "not to eq "
396
+ expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
397
+ end
398
+ end
399
+ )
390
400
 
391
- expect(program).
392
- to produce_output_when_run(expected_output).
393
- in_color(color_enabled)
401
+ expect(program).to produce_output_when_run(expected_output).in_color(
402
+ color_enabled
403
+ )
394
404
  end
395
405
  end
396
406
  end
@@ -412,7 +422,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
412
422
  }
413
423
  ]
414
424
  ]
415
- actual = [
425
+ actual = [
416
426
  [
417
427
  :h2,
418
428
  [:span, [:text, "Goodbye world"]],
@@ -432,56 +442,59 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
432
442
  TEST
433
443
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
434
444
 
435
- expected_output = build_expected_output(
436
- color_enabled: color_enabled,
437
- snippet: %|expect(actual).to eq(expected)|,
438
- expectation: proc {
439
- line do
440
- plain %|Expected |
441
- actual %|[[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, :role => "deprecated", :person => #<SuperDiff::Test::Person name: "Doc", age: 60> } }], :br]|
442
- end
443
-
444
- line do
445
- plain %| to eq |
446
- expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
447
- end
448
- },
449
- diff: proc {
450
- plain_line %| [|
451
- plain_line %| [|
452
- expected_line %|- :h1,|
453
- actual_line %|+ :h2,|
454
- plain_line %| [|
455
- plain_line %| :span,|
456
- plain_line %| [|
457
- plain_line %| :text,|
458
- expected_line %|- "Hello world"|
459
- actual_line %|+ "Goodbye world"|
460
- plain_line %| ]|
461
- plain_line %| ],|
462
- plain_line %| {|
463
- actual_line %|+ id: "hero",|
464
- plain_line %| class: "header",|
465
- plain_line %| data: {|
466
- expected_line %|- "sticky" => true,|
467
- actual_line %|+ "sticky" => false,|
468
- actual_line %|+ :role => "deprecated",|
469
- plain_line %| :person => #<SuperDiff::Test::Person {|
470
- expected_line %|- name: "Marty",|
471
- actual_line %|+ name: "Doc",|
472
- plain_line %| age: 60|
473
- plain_line %| }>|
474
- plain_line %| }|
475
- plain_line %| }|
476
- plain_line %| ],|
477
- actual_line %|+ :br|
478
- plain_line %| ]|
479
- },
480
- )
445
+ expected_output =
446
+ build_expected_output(
447
+ color_enabled: color_enabled,
448
+ snippet: "expect(actual).to eq(expected)",
449
+ expectation:
450
+ proc do
451
+ line do
452
+ plain "Expected "
453
+ actual %|[[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, :role => "deprecated", :person => #<SuperDiff::Test::Person name: "Doc", age: 60> } }], :br]|
454
+ end
455
+
456
+ line do
457
+ plain " to eq "
458
+ expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
459
+ end
460
+ end,
461
+ diff:
462
+ proc do
463
+ plain_line " ["
464
+ plain_line " ["
465
+ expected_line "- :h1,"
466
+ actual_line "+ :h2,"
467
+ plain_line " ["
468
+ plain_line " :span,"
469
+ plain_line " ["
470
+ plain_line " :text,"
471
+ expected_line %|- "Hello world"|
472
+ actual_line %|+ "Goodbye world"|
473
+ plain_line " ]"
474
+ plain_line " ],"
475
+ plain_line " {"
476
+ actual_line %|+ id: "hero",|
477
+ plain_line %| class: "header",|
478
+ plain_line " data: {"
479
+ expected_line %|- "sticky" => true,|
480
+ actual_line %|+ "sticky" => false,|
481
+ actual_line %|+ :role => "deprecated",|
482
+ plain_line " :person => #<SuperDiff::Test::Person {"
483
+ expected_line %|- name: "Marty",|
484
+ actual_line %|+ name: "Doc",|
485
+ plain_line " age: 60"
486
+ plain_line " }>"
487
+ plain_line " }"
488
+ plain_line " }"
489
+ plain_line " ],"
490
+ actual_line "+ :br"
491
+ plain_line " ]"
492
+ end
493
+ )
481
494
 
482
- expect(program).
483
- to produce_output_when_run(expected_output).
484
- in_color(color_enabled)
495
+ expect(program).to produce_output_when_run(expected_output).in_color(
496
+ color_enabled
497
+ )
485
498
  end
486
499
  end
487
500
 
@@ -505,26 +518,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
505
518
  TEST
506
519
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
507
520
 
508
- expected_output = build_expected_output(
509
- color_enabled: color_enabled,
510
- snippet: %|expect(value).not_to eq(value)|,
511
- newline_before_expectation: true,
512
- expectation: proc {
513
- line do
514
- plain %| Expected |
515
- actual %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
516
- end
517
-
518
- line do
519
- plain %|not to eq |
520
- expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
521
- end
522
- },
523
- )
521
+ expected_output =
522
+ build_expected_output(
523
+ color_enabled: color_enabled,
524
+ snippet: "expect(value).not_to eq(value)",
525
+ newline_before_expectation: true,
526
+ expectation:
527
+ proc do
528
+ line do
529
+ plain " Expected "
530
+ actual %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
531
+ end
532
+
533
+ line do
534
+ plain "not to eq "
535
+ expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
536
+ end
537
+ end
538
+ )
524
539
 
525
- expect(program).
526
- to produce_output_when_run(expected_output).
527
- in_color(color_enabled)
540
+ expect(program).to produce_output_when_run(expected_output).in_color(
541
+ color_enabled
542
+ )
528
543
  end
529
544
  end
530
545
  end
@@ -552,7 +567,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
552
567
  { name: "Chevy 4x4" }
553
568
  ]
554
569
  }
555
- actual = {
570
+ actual = {
556
571
  customer: {
557
572
  person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
558
573
  shipping_address: {
@@ -575,58 +590,61 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
575
590
  TEST
576
591
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
577
592
 
578
- expected_output = build_expected_output(
579
- color_enabled: color_enabled,
580
- snippet: %|expect(actual).to eq(expected)|,
581
- expectation: proc {
582
- line do
583
- plain %|Expected |
584
- actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly, Jr.", age: 17>, shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] }|
585
- end
586
-
587
- line do
588
- plain %| to eq |
589
- expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
590
- end
591
- },
592
- diff: proc {
593
- plain_line %| {|
594
- plain_line %| customer: {|
595
- plain_line %| person: #<SuperDiff::Test::Person {|
596
- expected_line %|- name: "Marty McFly",|
597
- actual_line %|+ name: "Marty McFly, Jr.",|
598
- plain_line %| age: 17|
599
- plain_line %| }>,|
600
- plain_line %| shipping_address: {|
601
- expected_line %|- line_1: "123 Main St.",|
602
- actual_line %|+ line_1: "456 Ponderosa Ct.",|
603
- plain_line %| city: "Hill Valley",|
604
- plain_line %| state: "CA",|
605
- plain_line %| zip: "90382"|
606
- plain_line %| }|
607
- plain_line %| },|
608
- plain_line %| items: [|
609
- plain_line %| {|
610
- plain_line %| name: "Fender Stratocaster",|
611
- plain_line %| cost: 100000,|
612
- plain_line %| options: [|
613
- plain_line %| "red",|
614
- plain_line %| "blue",|
615
- plain_line %| "green"|
616
- plain_line %| ]|
617
- plain_line %| },|
618
- plain_line %| {|
619
- expected_line %|- name: "Chevy 4x4"|
620
- actual_line %|+ name: "Mattel Hoverboard"|
621
- plain_line %| }|
622
- plain_line %| ]|
623
- plain_line %| }|
624
- },
625
- )
593
+ expected_output =
594
+ build_expected_output(
595
+ color_enabled: color_enabled,
596
+ snippet: "expect(actual).to eq(expected)",
597
+ expectation:
598
+ proc do
599
+ line do
600
+ plain "Expected "
601
+ actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly, Jr.", age: 17>, shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] }|
602
+ end
603
+
604
+ line do
605
+ plain " to eq "
606
+ expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
607
+ end
608
+ end,
609
+ diff:
610
+ proc do
611
+ plain_line " {"
612
+ plain_line " customer: {"
613
+ plain_line " person: #<SuperDiff::Test::Person {"
614
+ expected_line %|- name: "Marty McFly",|
615
+ actual_line %|+ name: "Marty McFly, Jr.",|
616
+ plain_line " age: 17"
617
+ plain_line " }>,"
618
+ plain_line " shipping_address: {"
619
+ expected_line %|- line_1: "123 Main St.",|
620
+ actual_line %|+ line_1: "456 Ponderosa Ct.",|
621
+ plain_line %| city: "Hill Valley",|
622
+ plain_line %| state: "CA",|
623
+ plain_line %| zip: "90382"|
624
+ plain_line " }"
625
+ plain_line " },"
626
+ plain_line " items: ["
627
+ plain_line " {"
628
+ plain_line %| name: "Fender Stratocaster",|
629
+ plain_line " cost: 100000,"
630
+ plain_line " options: ["
631
+ plain_line %| "red",|
632
+ plain_line %| "blue",|
633
+ plain_line %| "green"|
634
+ plain_line " ]"
635
+ plain_line " },"
636
+ plain_line " {"
637
+ expected_line %|- name: "Chevy 4x4"|
638
+ actual_line %|+ name: "Mattel Hoverboard"|
639
+ plain_line " }"
640
+ plain_line " ]"
641
+ plain_line " }"
642
+ end
643
+ )
626
644
 
627
- expect(program).
628
- to produce_output_when_run(expected_output).
629
- in_color(color_enabled)
645
+ expect(program).to produce_output_when_run(expected_output).in_color(
646
+ color_enabled
647
+ )
630
648
  end
631
649
  end
632
650
 
@@ -656,26 +674,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
656
674
  TEST
657
675
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
658
676
 
659
- expected_output = build_expected_output(
660
- color_enabled: color_enabled,
661
- snippet: %|expect(value).not_to eq(value)|,
662
- newline_before_expectation: true,
663
- expectation: proc {
664
- line do
665
- plain %| Expected |
666
- actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
667
- end
668
-
669
- line do
670
- plain %|not to eq |
671
- expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
672
- end
673
- },
674
- )
677
+ expected_output =
678
+ build_expected_output(
679
+ color_enabled: color_enabled,
680
+ snippet: "expect(value).not_to eq(value)",
681
+ newline_before_expectation: true,
682
+ expectation:
683
+ proc do
684
+ line do
685
+ plain " Expected "
686
+ actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
687
+ end
688
+
689
+ line do
690
+ plain "not to eq "
691
+ expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] }|
692
+ end
693
+ end
694
+ )
675
695
 
676
- expect(program).
677
- to produce_output_when_run(expected_output).
678
- in_color(color_enabled)
696
+ expect(program).to produce_output_when_run(expected_output).in_color(
697
+ color_enabled
698
+ )
679
699
  end
680
700
  end
681
701
  end
@@ -688,7 +708,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
688
708
  name: "Marty",
689
709
  age: 31,
690
710
  )
691
- actual = SuperDiff::Test::Customer.new(
711
+ actual = SuperDiff::Test::Customer.new(
692
712
  name: "Doc",
693
713
  shipping_address: :some_shipping_address,
694
714
  phone: "1234567890",
@@ -697,26 +717,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
697
717
  TEST
698
718
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
699
719
 
700
- expected_output = build_expected_output(
701
- color_enabled: color_enabled,
702
- snippet: %|expect(actual).to eq(expected)|,
703
- newline_before_expectation: true,
704
- expectation: proc {
705
- line do
706
- plain %|Expected |
707
- actual %|#<SuperDiff::Test::Customer name: "Doc", shipping_address: :some_shipping_address, phone: "1234567890">|
708
- end
709
-
710
- line do
711
- plain %| to eq |
712
- expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
713
- end
714
- },
715
- )
720
+ expected_output =
721
+ build_expected_output(
722
+ color_enabled: color_enabled,
723
+ snippet: "expect(actual).to eq(expected)",
724
+ newline_before_expectation: true,
725
+ expectation:
726
+ proc do
727
+ line do
728
+ plain "Expected "
729
+ actual %|#<SuperDiff::Test::Customer name: "Doc", shipping_address: :some_shipping_address, phone: "1234567890">|
730
+ end
731
+
732
+ line do
733
+ plain " to eq "
734
+ expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
735
+ end
736
+ end
737
+ )
716
738
 
717
- expect(program).
718
- to produce_output_when_run(expected_output).
719
- in_color(color_enabled)
739
+ expect(program).to produce_output_when_run(expected_output).in_color(
740
+ color_enabled
741
+ )
720
742
  end
721
743
  end
722
744
 
@@ -731,26 +753,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
731
753
  TEST
732
754
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
733
755
 
734
- expected_output = build_expected_output(
735
- color_enabled: color_enabled,
736
- snippet: %|expect(value).not_to eq(value)|,
737
- newline_before_expectation: true,
738
- expectation: proc {
739
- line do
740
- plain %| Expected |
741
- actual %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
742
- end
743
-
744
- line do
745
- plain %|not to eq |
746
- expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
747
- end
748
- },
749
- )
756
+ expected_output =
757
+ build_expected_output(
758
+ color_enabled: color_enabled,
759
+ snippet: "expect(value).not_to eq(value)",
760
+ newline_before_expectation: true,
761
+ expectation:
762
+ proc do
763
+ line do
764
+ plain " Expected "
765
+ actual %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
766
+ end
767
+
768
+ line do
769
+ plain "not to eq "
770
+ expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
771
+ end
772
+ end
773
+ )
750
774
 
751
- expect(program).
752
- to produce_output_when_run(expected_output).
753
- in_color(color_enabled)
775
+ expect(program).to produce_output_when_run(expected_output).in_color(
776
+ color_enabled
777
+ )
754
778
  end
755
779
  end
756
780
  end
@@ -763,7 +787,7 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
763
787
  name: "camera",
764
788
  quantity: 3,
765
789
  )
766
- actual = SuperDiff::Test::Player.new(
790
+ actual = SuperDiff::Test::Player.new(
767
791
  handle: "mcmire",
768
792
  character: "Jon",
769
793
  inventory: ["sword"],
@@ -775,27 +799,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
775
799
  TEST
776
800
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
777
801
 
778
- expected_output = build_expected_output(
779
- color_enabled: color_enabled,
780
- snippet: %|expect(actual).to eq(expected)|,
781
- newline_before_expectation: true,
782
- expectation: proc {
783
- line do
784
- plain %|Expected |
785
- actual %|#<SuperDiff::Test::Player @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>|
786
- end
787
-
788
- line do
789
- plain %| to eq |
790
- expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
791
- end
792
- },
793
- )
802
+ expected_output =
803
+ build_expected_output(
804
+ color_enabled: color_enabled,
805
+ snippet: "expect(actual).to eq(expected)",
806
+ newline_before_expectation: true,
807
+ expectation:
808
+ proc do
809
+ line do
810
+ plain "Expected "
811
+ actual %|#<SuperDiff::Test::Player @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>|
812
+ end
813
+
814
+ line do
815
+ plain " to eq "
816
+ expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
817
+ end
818
+ end
819
+ )
794
820
 
795
- expect(program).
796
- to produce_output_when_run(expected_output).
797
- in_color(color_enabled).
798
- removing_object_ids
821
+ expect(program).to produce_output_when_run(expected_output).in_color(
822
+ color_enabled
823
+ ).removing_object_ids
799
824
  end
800
825
  end
801
826
 
@@ -810,27 +835,28 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
810
835
  TEST
811
836
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
812
837
 
813
- expected_output = build_expected_output(
814
- color_enabled: color_enabled,
815
- snippet: %|expect(value).not_to eq(value)|,
816
- newline_before_expectation: true,
817
- expectation: proc {
818
- line do
819
- plain %| Expected |
820
- actual %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
821
- end
822
-
823
- line do
824
- plain %|not to eq |
825
- expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
826
- end
827
- },
828
- )
838
+ expected_output =
839
+ build_expected_output(
840
+ color_enabled: color_enabled,
841
+ snippet: "expect(value).not_to eq(value)",
842
+ newline_before_expectation: true,
843
+ expectation:
844
+ proc do
845
+ line do
846
+ plain " Expected "
847
+ actual %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
848
+ end
849
+
850
+ line do
851
+ plain "not to eq "
852
+ expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
853
+ end
854
+ end
855
+ )
829
856
 
830
- expect(program).
831
- to produce_output_when_run(expected_output).
832
- in_color(color_enabled).
833
- removing_object_ids
857
+ expect(program).to produce_output_when_run(expected_output).in_color(
858
+ color_enabled
859
+ ).removing_object_ids
834
860
  end
835
861
  end
836
862
  end
@@ -840,35 +866,38 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
840
866
  as_both_colored_and_uncolored do |color_enabled|
841
867
  snippet = <<~TEST.strip
842
868
  expected = { foo: nil }
843
- actual = { foo: [] }
869
+ actual = { foo: [] }
844
870
  expect(actual).to eq(expected)
845
871
  TEST
846
872
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
847
873
 
848
- expected_output = build_expected_output(
849
- color_enabled: color_enabled,
850
- snippet: %|expect(actual).to eq(expected)|,
851
- newline_before_expectation: true,
852
- expectation: proc {
853
- line do
854
- plain %|Expected |
855
- actual %|{ foo: [] }|
856
- plain %| to eq |
857
- expected %|{ foo: nil }|
858
- plain %|.|
859
- end
860
- },
861
- diff: proc {
862
- plain_line %| {|
863
- expected_line %|- foo: nil|
864
- actual_line %|+ foo: []|
865
- plain_line %| }|
866
- }
867
- )
874
+ expected_output =
875
+ build_expected_output(
876
+ color_enabled: color_enabled,
877
+ snippet: "expect(actual).to eq(expected)",
878
+ newline_before_expectation: true,
879
+ expectation:
880
+ proc do
881
+ line do
882
+ plain "Expected "
883
+ actual "{ foo: [] }"
884
+ plain " to eq "
885
+ expected "{ foo: nil }"
886
+ plain "."
887
+ end
888
+ end,
889
+ diff:
890
+ proc do
891
+ plain_line " {"
892
+ expected_line "- foo: nil"
893
+ actual_line "+ foo: []"
894
+ plain_line " }"
895
+ end
896
+ )
868
897
 
869
- expect(program).
870
- to produce_output_when_run(expected_output).
871
- in_color(color_enabled)
898
+ expect(program).to produce_output_when_run(expected_output).in_color(
899
+ color_enabled
900
+ )
872
901
  end
873
902
  end
874
903
  end
@@ -878,35 +907,38 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
878
907
  as_both_colored_and_uncolored do |color_enabled|
879
908
  snippet = <<~TEST.strip
880
909
  expected = { foo: nil }
881
- actual = { foo: {} }
910
+ actual = { foo: {} }
882
911
  expect(actual).to eq(expected)
883
912
  TEST
884
913
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
885
914
 
886
- expected_output = build_expected_output(
887
- color_enabled: color_enabled,
888
- snippet: %|expect(actual).to eq(expected)|,
889
- newline_before_expectation: true,
890
- expectation: proc {
891
- line do
892
- plain %|Expected |
893
- actual %|{ foo: {} }|
894
- plain %| to eq |
895
- expected %|{ foo: nil }|
896
- plain %|.|
897
- end
898
- },
899
- diff: proc {
900
- plain_line %| {|
901
- expected_line %|- foo: nil|
902
- actual_line %|+ foo: {}|
903
- plain_line %| }|
904
- }
905
- )
915
+ expected_output =
916
+ build_expected_output(
917
+ color_enabled: color_enabled,
918
+ snippet: "expect(actual).to eq(expected)",
919
+ newline_before_expectation: true,
920
+ expectation:
921
+ proc do
922
+ line do
923
+ plain "Expected "
924
+ actual "{ foo: {} }"
925
+ plain " to eq "
926
+ expected "{ foo: nil }"
927
+ plain "."
928
+ end
929
+ end,
930
+ diff:
931
+ proc do
932
+ plain_line " {"
933
+ expected_line "- foo: nil"
934
+ actual_line "+ foo: {}"
935
+ plain_line " }"
936
+ end
937
+ )
906
938
 
907
- expect(program).
908
- to produce_output_when_run(expected_output).
909
- in_color(color_enabled)
939
+ expect(program).to produce_output_when_run(expected_output).in_color(
940
+ color_enabled
941
+ )
910
942
  end
911
943
  end
912
944
  end
@@ -916,36 +948,38 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
916
948
  as_both_colored_and_uncolored do |color_enabled|
917
949
  snippet = <<~TEST.strip
918
950
  expected = { foo: nil }
919
- actual = { foo: SuperDiff::Test::EmptyClass.new }
951
+ actual = { foo: SuperDiff::Test::EmptyClass.new }
920
952
  expect(actual).to eq(expected)
921
953
  TEST
922
954
  program = make_plain_test_program(snippet, color_enabled: color_enabled)
923
955
 
924
- expected_output = build_expected_output(
925
- color_enabled: color_enabled,
926
- snippet: %|expect(actual).to eq(expected)|,
927
- newline_before_expectation: true,
928
- expectation: proc {
929
- line do
930
- plain %|Expected |
931
- actual %|{ foo: #<SuperDiff::Test::EmptyClass> }|
932
- plain %| to eq |
933
- expected %|{ foo: nil }|
934
- plain %|.|
935
- end
936
- },
937
- diff: proc {
938
- plain_line %| {|
939
- expected_line %|- foo: nil|
940
- actual_line %|+ foo: #<SuperDiff::Test::EmptyClass>|
941
- plain_line %| }|
942
- }
943
- )
956
+ expected_output =
957
+ build_expected_output(
958
+ color_enabled: color_enabled,
959
+ snippet: "expect(actual).to eq(expected)",
960
+ newline_before_expectation: true,
961
+ expectation:
962
+ proc do
963
+ line do
964
+ plain "Expected "
965
+ actual "{ foo: #<SuperDiff::Test::EmptyClass> }"
966
+ plain " to eq "
967
+ expected "{ foo: nil }"
968
+ plain "."
969
+ end
970
+ end,
971
+ diff:
972
+ proc do
973
+ plain_line " {"
974
+ expected_line "- foo: nil"
975
+ actual_line "+ foo: #<SuperDiff::Test::EmptyClass>"
976
+ plain_line " }"
977
+ end
978
+ )
944
979
 
945
- expect(program).
946
- to produce_output_when_run(expected_output).
947
- in_color(color_enabled).
948
- removing_object_ids
980
+ expect(program).to produce_output_when_run(expected_output).in_color(
981
+ color_enabled
982
+ ).removing_object_ids
949
983
  end
950
984
  end
951
985
  end
@@ -953,4 +987,8 @@ RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
953
987
  it_behaves_like "a matcher that supports elided diffs" do
954
988
  let(:matcher) { :eq }
955
989
  end
990
+
991
+ it_behaves_like "a matcher that supports a toggleable key" do
992
+ let(:matcher) { :eq }
993
+ end
956
994
  end