super_diff 0.9.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) 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 +22 -18
  6. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
  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 +20 -11
  18. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  19. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
  20. data/lib/super_diff/active_support/object_inspection.rb +1 -1
  21. data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
  22. data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
  23. data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
  24. data/lib/super_diff/active_support/operation_trees.rb +1 -1
  25. data/lib/super_diff/active_support.rb +6 -10
  26. data/lib/super_diff/colorized_document_extensions.rb +2 -4
  27. data/lib/super_diff/configuration.rb +14 -8
  28. data/lib/super_diff/csi/color.rb +4 -4
  29. data/lib/super_diff/csi/colorized_document.rb +12 -16
  30. data/lib/super_diff/csi/document.rb +8 -19
  31. data/lib/super_diff/csi/eight_bit_color.rb +19 -19
  32. data/lib/super_diff/csi/four_bit_color.rb +82 -31
  33. data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
  34. data/lib/super_diff/csi/uncolorized_document.rb +2 -6
  35. data/lib/super_diff/csi.rb +10 -14
  36. data/lib/super_diff/diff_formatters/collection.rb +35 -41
  37. data/lib/super_diff/differs/date_like.rb +15 -0
  38. data/lib/super_diff/differs/default_object.rb +1 -1
  39. data/lib/super_diff/differs/defaults.rb +2 -1
  40. data/lib/super_diff/differs/main.rb +2 -13
  41. data/lib/super_diff/differs.rb +1 -0
  42. data/lib/super_diff/equality_matchers/array.rb +10 -12
  43. data/lib/super_diff/equality_matchers/base.rb +1 -1
  44. data/lib/super_diff/equality_matchers/default.rb +2 -4
  45. data/lib/super_diff/equality_matchers/defaults.rb +1 -1
  46. data/lib/super_diff/equality_matchers/hash.rb +10 -12
  47. data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
  48. data/lib/super_diff/equality_matchers/primitive.rb +10 -12
  49. data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
  50. data/lib/super_diff/equality_matchers.rb +1 -1
  51. data/lib/super_diff/errors.rb +2 -6
  52. data/lib/super_diff/gem_version.rb +3 -3
  53. data/lib/super_diff/helpers.rb +10 -10
  54. data/lib/super_diff/implementation_checks.rb +2 -2
  55. data/lib/super_diff/line.rb +3 -3
  56. data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
  57. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
  58. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
  59. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  60. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
  61. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
  62. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
  63. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  64. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
  65. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
  66. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
  67. data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
  68. data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
  69. data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
  70. data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
  72. data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
  73. data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
  74. data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
  75. data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
  76. data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
  77. data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
  78. data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
  79. data/lib/super_diff/object_inspection/nodes.rb +7 -7
  80. data/lib/super_diff/object_inspection.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/array.rb +12 -11
  82. data/lib/super_diff/operation_tree_builders/base.rb +17 -15
  83. data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
  84. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  85. data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
  86. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  87. data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
  88. data/lib/super_diff/operation_tree_builders/main.rb +4 -11
  89. data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
  90. data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
  91. data/lib/super_diff/operation_tree_builders.rb +2 -1
  92. data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
  93. data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
  94. data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
  95. data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
  96. data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
  97. data/lib/super_diff/operation_tree_flatteners.rb +3 -3
  98. data/lib/super_diff/operation_trees/base.rb +3 -5
  99. data/lib/super_diff/operation_trees/default_object.rb +1 -3
  100. data/lib/super_diff/operations/binary_operation.rb +2 -2
  101. data/lib/super_diff/operations/unary_operation.rb +1 -1
  102. data/lib/super_diff/rails.rb +2 -1
  103. data/lib/super_diff/recursion_guard.rb +5 -4
  104. data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
  105. data/lib/super_diff/rspec/differ.rb +6 -13
  106. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
  107. data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
  108. data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
  109. data/lib/super_diff/rspec/differs.rb +3 -3
  110. data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
  111. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
  112. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
  113. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
  114. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
  115. data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
  116. data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
  117. data/lib/super_diff/rspec/monkey_patches.rb +180 -123
  118. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  119. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
  120. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
  121. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  122. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
  123. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
  124. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
  125. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  126. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  127. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
  128. data/lib/super_diff/rspec/object_inspection.rb +1 -1
  129. data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
  130. data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
  131. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
  132. data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
  133. data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
  134. data/lib/super_diff/rspec.rb +17 -18
  135. data/lib/super_diff/tiered_lines_elider.rb +87 -115
  136. data/lib/super_diff/tiered_lines_formatter.rb +5 -9
  137. data/lib/super_diff/version.rb +1 -1
  138. data/lib/super_diff.rb +13 -9
  139. data/spec/examples.txt +541 -483
  140. data/spec/integration/rails/active_record_spec.rb +3 -1
  141. data/spec/integration/rails/engines_spec.rb +25 -0
  142. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
  143. data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
  144. data/spec/integration/rspec/be_matcher_spec.rb +360 -320
  145. data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
  146. data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
  147. data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
  148. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
  149. data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
  150. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  151. data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
  152. data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
  153. data/spec/integration/rspec/include_matcher_spec.rb +327 -225
  154. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  155. data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
  156. data/spec/integration/rspec/match_matcher_spec.rb +916 -903
  157. data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
  158. data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
  159. data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
  160. data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
  161. data/spec/internal/log/test.log +0 -0
  162. data/spec/spec_helper.rb +20 -20
  163. data/spec/support/command_runner.rb +34 -57
  164. data/spec/support/integration/helpers.rb +44 -32
  165. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
  166. data/spec/support/integration/matchers.rb +34 -0
  167. data/spec/support/integration/test_programs/base.rb +17 -22
  168. data/spec/support/integration/test_programs/plain.rb +6 -0
  169. data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
  170. data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
  171. data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
  172. data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
  173. data/spec/support/models/active_record/person.rb +6 -4
  174. data/spec/support/models/active_record/shipping_address.rb +9 -10
  175. data/spec/support/models/customer.rb +2 -4
  176. data/spec/support/models/player.rb +3 -6
  177. data/spec/support/models/shipping_address.rb +4 -13
  178. data/spec/support/shared_examples/active_record.rb +258 -240
  179. data/spec/support/shared_examples/active_support.rb +174 -51
  180. data/spec/support/shared_examples/elided_diffs.rb +447 -423
  181. data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
  182. data/spec/support/shared_examples/key.rb +123 -0
  183. data/spec/support/unit/helpers.rb +1 -3
  184. data/spec/support/unit/matchers/match_output.rb +12 -13
  185. data/spec/unit/active_record/object_inspection_spec.rb +222 -206
  186. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  187. data/spec/unit/equality_matchers/main_spec.rb +1049 -984
  188. data/spec/unit/helpers_spec.rb +14 -21
  189. data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
  190. data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
  191. data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
  192. data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
  193. data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
  194. data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
  195. data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
  196. data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
  197. data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
  198. data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
  199. data/spec/unit/rspec/matchers/include_spec.rb +2 -2
  200. data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
  201. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  202. data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
  203. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  204. data/spec/unit/rspec/object_inspection_spec.rb +351 -326
  205. data/spec/unit/super_diff_spec.rb +1594 -1437
  206. data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
  207. data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
  208. data/super_diff.gemspec +13 -12
  209. metadata +88 -75
  210. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  211. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
  212. data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
@@ -28,16 +28,13 @@ class CommandRunner
28
28
  Command #{command.inspect} failed, exiting with status #{exit_status}.
29
29
  MESSAGE
30
30
 
31
- if output
32
- message << <<-MESSAGE
31
+ message << <<-MESSAGE if output
33
32
  Output:
34
33
  #{
35
- SuperDiff::Test::OutputHelpers.divider("START") +
36
- output +
37
- SuperDiff::Test::OutputHelpers.divider("END")
38
- }
34
+ SuperDiff::Test::OutputHelpers.divider("START") + output +
35
+ SuperDiff::Test::OutputHelpers.divider("END")
36
+ }
39
37
  MESSAGE
40
- end
41
38
 
42
39
  message
43
40
  end
@@ -66,16 +63,13 @@ Output:
66
63
  Command #{formatted_command.inspect} timed out after #{timeout} seconds.
67
64
  MESSAGE
68
65
 
69
- if output
70
- message << <<-MESSAGE
66
+ message << <<-MESSAGE if output
71
67
  Output:
72
68
  #{
73
- SuperDiff::Test::OutputHelpers.divider("START") +
74
- output +
75
- SuperDiff::Test::OutputHelpers.divider("END")
76
- }
69
+ SuperDiff::Test::OutputHelpers.divider("START") + output +
70
+ SuperDiff::Test::OutputHelpers.divider("END")
71
+ }
77
72
  MESSAGE
78
- end
79
73
 
80
74
  message
81
75
  end
@@ -96,26 +90,20 @@ Output:
96
90
  end
97
91
 
98
92
  attr_reader :status, :options, :env
99
- attr_accessor :run_quickly, :run_successfully, :retries,
100
- :timeout
93
+ attr_accessor :run_quickly, :run_successfully, :retries, :timeout
101
94
 
102
95
  def initialize(*args)
103
96
  @reader, @writer = IO.pipe
104
97
  options = (args.last.is_a?(Hash) ? args.pop : {})
105
98
  @args = args
106
- @options = options.merge(
107
- err: [:child, :out],
108
- out: @writer,
109
- )
99
+ @options = options.merge(err: %i[child out], out: @writer)
110
100
  @env = extract_env_from(@options)
111
101
 
112
102
  @process = ChildProcess.build(*command)
113
- @env.each do |key, value|
114
- @process.environment[key] = value
115
- end
103
+ @env.each { |key, value| @process.environment[key] = value }
116
104
  @process.io.stdout = @process.io.stderr = @writer
117
105
 
118
- @wrapper = -> (block) { block.call }
106
+ @wrapper = ->(block) { block.call }
119
107
  self.directory = Dir.pwd
120
108
  @run_quickly = false
121
109
  @run_successfully = false
@@ -137,43 +125,36 @@ Output:
137
125
  end
138
126
 
139
127
  def formatted_command
140
- [formatted_env, Shellwords.join(command)].
141
- reject(&:empty?).
142
- join(" ")
128
+ [formatted_env, Shellwords.join(command)].reject(&:empty?).join(" ")
143
129
  end
144
130
 
145
131
  def run
146
132
  possibly_running_quickly do
147
133
  run_with_debugging
148
134
 
149
- if run_successfully && !success?
150
- fail!
151
- end
135
+ fail! if run_successfully && !success?
152
136
  end
153
137
 
154
138
  self
155
139
  end
156
140
 
157
141
  def stop
158
- if !writer.closed?
159
- writer.close
160
- end
142
+ writer.close if !writer.closed?
161
143
  end
162
144
 
163
145
  def output
164
- @_output ||= begin
165
- stop
166
- reader.read
167
- end
146
+ @_output ||=
147
+ begin
148
+ stop
149
+ reader.read
150
+ end
168
151
  end
169
152
 
170
153
  def elided_output
171
154
  lines = output.split(/\n/)
172
155
  new_lines = lines[0..4]
173
156
 
174
- if lines.size > 10
175
- new_lines << "(...#{lines.size - 10} more lines...)"
176
- end
157
+ new_lines << "(...#{lines.size - 10} more lines...)" if lines.size > 10
177
158
 
178
159
  new_lines << lines[-5..-1]
179
160
  new_lines.join("\n")
@@ -189,10 +170,10 @@ Output:
189
170
 
190
171
  def fail!
191
172
  raise CommandFailedError.create(
192
- command: formatted_command,
193
- exit_status: exit_status,
194
- output: output,
195
- )
173
+ command: formatted_command,
174
+ exit_status: exit_status,
175
+ output: output
176
+ )
196
177
  end
197
178
 
198
179
  def has_output?(expected_output)
@@ -210,9 +191,9 @@ Output:
210
191
  private
211
192
 
212
193
  def extract_env_from(options)
213
- options.delete(:env) { {} }.reduce({}) do |hash, (key, value)|
214
- hash.merge(key.to_s => value)
215
- end
194
+ options
195
+ .delete(:env) { {} }
196
+ .reduce({}) { |hash, (key, value)| hash.merge(key.to_s => value) }
216
197
  end
217
198
 
218
199
  def command
@@ -239,9 +220,7 @@ Output:
239
220
  run_with_wrapper
240
221
 
241
222
  debug do
242
- "\n" +
243
- SuperDiff::Test::OutputHelpers.divider("START") +
244
- output +
223
+ "\n" + SuperDiff::Test::OutputHelpers.divider("START") + output +
245
224
  SuperDiff::Test::OutputHelpers.divider("END")
246
225
  end
247
226
  end
@@ -254,10 +233,10 @@ Output:
254
233
  stop
255
234
 
256
235
  raise CommandTimedOutError.create(
257
- command: formatted_command,
258
- timeout: timeout,
259
- output: output,
260
- )
236
+ command: formatted_command,
237
+ timeout: timeout,
238
+ output: output
239
+ )
261
240
  end
262
241
  else
263
242
  yield
@@ -269,8 +248,6 @@ Output:
269
248
  end
270
249
 
271
250
  def debug
272
- if debugging_enabled?
273
- puts yield
274
- end
251
+ puts yield if debugging_enabled?
275
252
  end
276
253
  end
@@ -3,22 +3,20 @@ module SuperDiff
3
3
  PROJECT_DIRECTORY = Pathname.new("../../..").expand_path(__dir__)
4
4
 
5
5
  def as_both_colored_and_uncolored
6
- [true, false].each do |color_enabled|
7
- yield color_enabled
8
- end
6
+ [true, false].each { |color_enabled| yield color_enabled }
9
7
  end
10
8
 
11
9
  def make_plain_test_program(
12
10
  test,
13
11
  color_enabled:,
14
- configuration: {},
12
+ super_diff_configuration: {},
15
13
  preserve_as_whole_file: false
16
14
  )
17
15
  TestPrograms::Plain.new(
18
16
  test,
19
17
  color_enabled: color_enabled,
20
- configuration: configuration,
21
- preserve_as_whole_file: preserve_as_whole_file,
18
+ super_diff_configuration: super_diff_configuration,
19
+ preserve_as_whole_file: preserve_as_whole_file
22
20
  )
23
21
  end
24
22
 
@@ -34,27 +32,38 @@ module SuperDiff
34
32
  TestPrograms::RSpecRails.new(test, color_enabled: color_enabled)
35
33
  end
36
34
 
35
+ def make_rspec_rails_engine_with_action_controller_program(
36
+ test,
37
+ color_enabled:
38
+ )
39
+ TestPrograms::RspecRailsEngineWithActionController.new(
40
+ test,
41
+ color_enabled: color_enabled
42
+ )
43
+ end
44
+
37
45
  def build_expected_output(
38
46
  color_enabled:,
39
47
  snippet:,
40
48
  expectation:,
49
+ test_name: "test passes",
50
+ key_enabled: true,
41
51
  newline_before_expectation: false,
42
52
  indentation: 7,
43
- diff: nil
53
+ diff: nil,
54
+ extra_failure_lines: nil
44
55
  )
45
56
  colored(color_enabled: color_enabled) do
46
57
  line "Failures:\n"
47
58
 
48
- line "1) test passes", indent_by: 2
59
+ line "1) #{test_name}", indent_by: 2
49
60
 
50
61
  line indent_by: 5 do
51
62
  bold "Failure/Error: "
52
63
  plain snippet
53
64
  end
54
65
 
55
- if diff || newline_before_expectation
56
- newline
57
- end
66
+ newline if diff || newline_before_expectation
58
67
 
59
68
  indent by: indentation do
60
69
  evaluate_block(&expectation)
@@ -64,32 +73,30 @@ module SuperDiff
64
73
 
65
74
  white_line "Diff:"
66
75
 
67
- newline
76
+ if key_enabled
77
+ newline
68
78
 
69
- line do
70
- blue "┌ (Key) ──────────────────────────┐"
71
- end
79
+ line { blue "┌ (Key) ──────────────────────────┐" }
72
80
 
73
- line do
74
- blue "│ "
75
- magenta "‹-› in expected, not in actual"
76
- blue " │"
77
- end
81
+ line do
82
+ blue "│ "
83
+ magenta "‹-› in expected, not in actual"
84
+ blue " │"
85
+ end
78
86
 
79
- line do
80
- blue "│ "
81
- yellow "‹+› in actual, not in expected"
82
- blue " │"
83
- end
87
+ line do
88
+ blue "│ "
89
+ yellow "‹+› in actual, not in expected"
90
+ blue " │"
91
+ end
84
92
 
85
- line do
86
- blue "│ "
87
- text "‹ › in both expected and actual"
88
- blue " │"
89
- end
93
+ line do
94
+ blue "│ "
95
+ text "‹ › in both expected and actual"
96
+ blue " │"
97
+ end
90
98
 
91
- line do
92
- blue "└─────────────────────────────────┘"
99
+ line { blue "└─────────────────────────────────┘" }
93
100
  end
94
101
 
95
102
  newline
@@ -99,6 +106,11 @@ module SuperDiff
99
106
  newline
100
107
  end
101
108
  end
109
+
110
+ if extra_failure_lines
111
+ newline
112
+ evaluate_block(&extra_failure_lines)
113
+ end
102
114
  end
103
115
  end
104
116
 
@@ -32,31 +32,35 @@ module SuperDiff
32
32
  "Expected output of test " +
33
33
  (expect_output_to_contain_color? ? "to " : "not to ") +
34
34
  "contain color, but " +
35
- (expect_output_to_contain_color? ? "it did not" : "it did") +
36
- "."
35
+ (expect_output_to_contain_color? ? "it did not" : "it did") + "."
37
36
  else
38
37
  message =
39
38
  "Expected test to produce #{expect_output_to_contain_color? ? "colored" : "uncolored"} output, but it did not.\n\n" +
40
- "Expected output to contain:\n\n" +
41
- SuperDiff::Test::OutputHelpers.bookended(expected_output) +
42
- "\n" +
43
- "Actual output:\n\n" +
44
- SuperDiff::Test::OutputHelpers.bookended(actual_output)
45
-
46
- if ["1", "true"].include?(ENV["SHOW_DIFF"])
47
- ::RSpec::Matchers::ExpectedsForMultipleDiffs.
48
- from(expected_output).
49
- message_with_diff(
50
- message,
51
- ::RSpec::Expectations.differ,
52
- actual_output,
53
- )
39
+ "Expected output to contain:\n\n" +
40
+ SuperDiff::Test::OutputHelpers.bookended(expected_output) + "\n" +
41
+ "Actual output:\n\n" +
42
+ SuperDiff::Test::OutputHelpers.bookended(actual_output)
43
+
44
+ if %w[1 true].include?(ENV["SHOW_DIFF"])
45
+ ::RSpec::Matchers::ExpectedsForMultipleDiffs.from(
46
+ expected_output
47
+ ).message_with_diff(
48
+ message,
49
+ ::RSpec::Expectations.differ,
50
+ actual_output
51
+ )
54
52
  else
55
53
  message
56
54
  end
57
55
  end
58
56
  end
59
57
 
58
+ def failure_message_when_negated
59
+ "Expected output of test not to produce output, but it did.\n\n" +
60
+ "Actual output:\n\n" +
61
+ SuperDiff::Test::OutputHelpers.bookended(actual_output)
62
+ end
63
+
60
64
  private
61
65
 
62
66
  attr_reader :expected_output, :program, :output_processor
@@ -75,15 +79,16 @@ module SuperDiff
75
79
  end
76
80
 
77
81
  def actual_output
78
- @_actual_output ||= begin
79
- output = program.run.output.strip
82
+ @_actual_output ||=
83
+ begin
84
+ output = program.run.output.strip
80
85
 
81
- if output_processor
82
- output.gsub!(output_processor[0], output_processor[1])
83
- end
86
+ if output_processor
87
+ output.gsub!(output_processor[0], output_processor[1])
88
+ end
84
89
 
85
- output
86
- end
90
+ output
91
+ end
87
92
  end
88
93
 
89
94
  def presence_of_color_matches?
@@ -32,6 +32,40 @@ module SuperDiff
32
32
  PassWithSinglelineFailureMessageMatcher.new
33
33
  end
34
34
 
35
+ RSpec::Matchers.define :failing_custom_matcher_from_dsl do |value|
36
+ match { false }
37
+
38
+ description do
39
+ "custom matcher defined via the DSL with value #{value.inspect}"
40
+ end
41
+ end
42
+
43
+ def failing_custom_matcher_from_scratch(value)
44
+ FailingCustomMatcherFromScratch.new(value)
45
+ end
46
+
47
+ class FailingCustomMatcherFromScratch
48
+ def initialize(value)
49
+ @value = value
50
+ end
51
+
52
+ def matches?(_)
53
+ false
54
+ end
55
+
56
+ def description
57
+ "custom matcher defined from scratch with value #{value.inspect}"
58
+ end
59
+
60
+ def failure_message
61
+ "Expected custom matcher not to fail, but did"
62
+ end
63
+
64
+ private
65
+
66
+ attr_reader :value
67
+ end
68
+
35
69
  class FailWithIndentedMultilineFailureMessageMatcher
36
70
  def matches?(_)
37
71
  false
@@ -13,12 +13,12 @@ module SuperDiff
13
13
  def initialize(
14
14
  code,
15
15
  color_enabled:,
16
- configuration: {},
16
+ super_diff_configuration: {},
17
17
  preserve_as_whole_file: false
18
18
  )
19
19
  @code = code.strip
20
20
  @color_enabled = color_enabled
21
- @configuration = configuration
21
+ @super_diff_configuration = super_diff_configuration
22
22
  @preserve_as_whole_file = preserve_as_whole_file
23
23
  end
24
24
 
@@ -38,7 +38,7 @@ module SuperDiff
38
38
 
39
39
  private
40
40
 
41
- attr_reader :code, :configuration
41
+ attr_reader :code, :super_diff_configuration
42
42
 
43
43
  def color_enabled?
44
44
  @color_enabled
@@ -57,15 +57,15 @@ module SuperDiff
57
57
  else
58
58
  CommandRunner.run(
59
59
  Shellwords.join(command),
60
- env: { 'DISABLE_PRY' => 'true' },
60
+ env: {
61
+ "DISABLE_PRY" => "true"
62
+ }
61
63
  )
62
64
  end
63
65
  end
64
66
 
65
67
  def command
66
- if ENV["RAILS_ENV"]
67
- raise "RAILS_ENV is being set somehow?!"
68
- end
68
+ raise "RAILS_ENV is being set somehow?!" if ENV["RAILS_ENV"]
69
69
 
70
70
  if zeus_running?
71
71
  [
@@ -74,16 +74,11 @@ module SuperDiff
74
74
  color_option,
75
75
  "--no-pry",
76
76
  tempfile.to_s,
77
- "--configuration",
78
- JSON.generate(configuration),
77
+ "--super-diff-configuration",
78
+ JSON.generate(super_diff_configuration)
79
79
  ]
80
80
  else
81
- [
82
- "rspec",
83
- "--options",
84
- "/tmp/dummy-rspec-config",
85
- tempfile.to_s,
86
- ]
81
+ ["rspec", "--options", "/tmp/dummy-rspec-config", tempfile.to_s]
87
82
  end
88
83
  end
89
84
 
@@ -96,12 +91,13 @@ module SuperDiff
96
91
  end
97
92
 
98
93
  def tempfile
99
- @_tempfile ||= begin
100
- TEMP_DIRECTORY.mkpath
101
- TEMP_DIRECTORY.join("integration_spec.rb").tap do |file|
102
- file.write(program)
94
+ @_tempfile ||=
95
+ begin
96
+ TEMP_DIRECTORY.mkpath
97
+ TEMP_DIRECTORY
98
+ .join("integration_spec.rb")
99
+ .tap { |file| file.write(program) }
103
100
  end
104
- end
105
101
  end
106
102
 
107
103
  def program
@@ -114,9 +110,8 @@ module SuperDiff
114
110
  test_plan = TestPlan.new(
115
111
  using_outside_of_zeus: true,
116
112
  color_enabled: #{color_enabled?.inspect},
117
- configuration: #{configuration.inspect}
113
+ super_diff_configuration: #{super_diff_configuration.inspect}
118
114
  )
119
- test_plan.boot
120
115
  #{test_plan_prelude}
121
116
  test_plan.#{test_plan_command}
122
117
 
@@ -4,6 +4,12 @@ module SuperDiff
4
4
  class Plain < Base
5
5
  protected
6
6
 
7
+ def test_plan_prelude
8
+ <<~PRELUDE.strip
9
+ test_plan.boot
10
+ PRELUDE
11
+ end
12
+
7
13
  def test_plan_command
8
14
  "run_plain_test"
9
15
  end
@@ -5,7 +5,10 @@ module SuperDiff
5
5
  protected
6
6
 
7
7
  def test_plan_prelude
8
- "test_plan.boot_active_record"
8
+ <<~PRELUDE.strip
9
+ test_plan.boot
10
+ test_plan.boot_active_record
11
+ PRELUDE
9
12
  end
10
13
 
11
14
  def test_plan_command
@@ -5,7 +5,10 @@ module SuperDiff
5
5
  protected
6
6
 
7
7
  def test_plan_prelude
8
- "test_plan.boot_active_support"
8
+ <<~PRELUDE.strip
9
+ test_plan.boot
10
+ test_plan.boot_active_support
11
+ PRELUDE
9
12
  end
10
13
 
11
14
  def test_plan_command
@@ -5,7 +5,10 @@ module SuperDiff
5
5
  protected
6
6
 
7
7
  def test_plan_prelude
8
- "test_plan.boot_active_record"
8
+ <<~PRELUDE.strip
9
+ test_plan.boot
10
+ test_plan.boot_active_record
11
+ PRELUDE
9
12
  end
10
13
 
11
14
  def test_plan_command
@@ -0,0 +1,20 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecRailsEngineWithActionController < Base
5
+ protected
6
+
7
+ def test_plan_prelude
8
+ <<~PRELUDE.strip
9
+ test_plan.boot
10
+ test_plan.boot_rails_engine_with_action_controller
11
+ PRELUDE
12
+ end
13
+
14
+ def test_plan_command
15
+ "run_rspec_rails_test"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -11,9 +11,11 @@ end
11
11
 
12
12
  RSpec.configure do |config|
13
13
  config.before do
14
- ActiveRecord::Base.connection.create_table(:people, force: true) do |t|
15
- t.string :name, null: false
16
- t.integer :age, null: false
17
- end
14
+ ActiveRecord::Base
15
+ .connection
16
+ .create_table(:people, force: true) do |t|
17
+ t.string :name, null: false
18
+ t.integer :age, null: false
19
+ end
18
20
  end
19
21
  end
@@ -11,15 +11,14 @@ end
11
11
 
12
12
  RSpec.configure do |config|
13
13
  config.before do
14
- ActiveRecord::Base.connection.create_table(
15
- :shipping_addresses,
16
- force: true,
17
- ) do |t|
18
- t.string :line_1, null: false, default: ""
19
- t.string :line_2, null: false, default: ""
20
- t.string :city, null: false, default: ""
21
- t.string :state, null: false, default: ""
22
- t.string :zip, null: false, default: ""
23
- end
14
+ ActiveRecord::Base
15
+ .connection
16
+ .create_table(:shipping_addresses, force: true) do |t|
17
+ t.string :line_1, null: false, default: ""
18
+ t.string :line_2, null: false, default: ""
19
+ t.string :city, null: false, default: ""
20
+ t.string :state, null: false, default: ""
21
+ t.string :zip, null: false, default: ""
22
+ end
24
23
  end
25
24
  end
@@ -10,10 +10,8 @@ module SuperDiff
10
10
  end
11
11
 
12
12
  def ==(other)
13
- other.is_a?(self.class) &&
14
- other.name == name &&
15
- other.shipping_address == shipping_address &&
16
- other.phone == phone
13
+ other.is_a?(self.class) && other.name == name &&
14
+ other.shipping_address == shipping_address && other.phone == phone
17
15
  end
18
16
 
19
17
  def attributes_for_super_diff
@@ -20,12 +20,9 @@ module SuperDiff
20
20
  end
21
21
 
22
22
  def ==(other)
23
- other.is_a?(self.class) &&
24
- other.handle == handle &&
25
- other.character == character &&
26
- other.inventory == inventory &&
27
- other.shields == shields &&
28
- other.health == health &&
23
+ other.is_a?(self.class) && other.handle == handle &&
24
+ other.character == character && other.inventory == inventory &&
25
+ other.shields == shields && other.health == health &&
29
26
  other.ultimate == ultimate
30
27
  end
31
28
  end