super_diff 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -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,9 +3,7 @@ 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(
@@ -18,7 +16,7 @@ module SuperDiff
18
16
  test,
19
17
  color_enabled: color_enabled,
20
18
  configuration: configuration,
21
- preserve_as_whole_file: preserve_as_whole_file,
19
+ preserve_as_whole_file: preserve_as_whole_file
22
20
  )
23
21
  end
24
22
 
@@ -34,10 +32,23 @@ module SuperDiff
34
32
  TestPrograms::RSpecRails.new(test, color_enabled: color_enabled)
35
33
  end
36
34
 
35
+ def make_rspec_rails_engine_program(
36
+ test,
37
+ color_enabled:,
38
+ combustion_initialize:
39
+ )
40
+ TestPrograms::RspecRailsEngine.new(
41
+ test,
42
+ color_enabled: color_enabled,
43
+ combustion_initialize: combustion_initialize
44
+ )
45
+ end
46
+
37
47
  def build_expected_output(
38
48
  color_enabled:,
39
49
  snippet:,
40
50
  expectation:,
51
+ key_enabled: true,
41
52
  newline_before_expectation: false,
42
53
  indentation: 7,
43
54
  diff: nil
@@ -52,9 +63,7 @@ module SuperDiff
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
@@ -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?
@@ -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
  [
@@ -75,15 +75,10 @@ module SuperDiff
75
75
  "--no-pry",
76
76
  tempfile.to_s,
77
77
  "--configuration",
78
- JSON.generate(configuration),
78
+ JSON.generate(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
@@ -116,7 +112,6 @@ module SuperDiff
116
112
  color_enabled: #{color_enabled?.inspect},
117
113
  configuration: #{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,30 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecRailsEngine < Base
5
+ def initialize(*args, combustion_initialize:, **options)
6
+ super(*args, **options)
7
+ @combustion_initialize = combustion_initialize
8
+ end
9
+
10
+ protected
11
+
12
+ def test_plan_prelude
13
+ <<~PRELUDE.strip
14
+ test_plan.boot_rails_engine(
15
+ combustion_initialize: #{combustion_initialize.inspect}
16
+ )
17
+ PRELUDE
18
+ end
19
+
20
+ def test_plan_command
21
+ "run_rspec_rails_test"
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :combustion_initialize
27
+ end
28
+ end
29
+ end
30
+ 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
@@ -12,22 +12,13 @@ module SuperDiff
12
12
  end
13
13
 
14
14
  def ==(other)
15
- other.is_a?(self.class) &&
16
- other.line_1 == line_1 &&
17
- other.line_2 == line_2 &&
18
- other.city == city &&
19
- other.state == state &&
20
- other.zip == zip
15
+ other.is_a?(self.class) && other.line_1 == line_1 &&
16
+ other.line_2 == line_2 && other.city == city &&
17
+ other.state == state && other.zip == zip
21
18
  end
22
19
 
23
20
  def attributes_for_super_diff
24
- {
25
- line_1: line_1,
26
- line_2: line_2,
27
- city: city,
28
- state: state,
29
- zip: zip
30
- }
21
+ { line_1: line_1, line_2: line_2, city: city, state: state, zip: zip }
31
22
  end
32
23
  end
33
24
  end