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
@@ -60,19 +60,22 @@ module RSpec
60
60
  if code_or_symbol
61
61
  if (config_method = config_colors_to_methods[code_or_symbol])
62
62
  console_code_for RSpec.configuration.__send__(config_method)
63
- elsif RSpec::Core::Formatters::ConsoleCodes::VT100_CODE_VALUES.key?(code_or_symbol)
63
+ elsif RSpec::Core::Formatters::ConsoleCodes::VT100_CODE_VALUES.key?(
64
+ code_or_symbol
65
+ )
64
66
  code_or_symbol
65
67
  else
66
- RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.fetch(code_or_symbol) do
68
+ RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.fetch(
67
69
  code_or_symbol
68
- end
70
+ ) { code_or_symbol }
69
71
  end
70
72
  end
71
73
  end
72
74
 
73
75
  # Patch so it does not apply a color if code_or_symbol is nil
74
76
  def wrap(text, code_or_symbol)
75
- if RSpec.configuration.color_enabled? && code = console_code_for(code_or_symbol)
77
+ if SuperDiff.configuration.color_enabled? &&
78
+ code = console_code_for(code_or_symbol)
76
79
  "\e[#{code}m#{text}\e[0m"
77
80
  else
78
81
  text
@@ -86,50 +89,56 @@ module RSpec
86
89
  RESET_CODE = "\e[0m"
87
90
 
88
91
  SuperDiff.insert_overrides(self) do
89
- def initialize(exception, example, options={})
90
- @exception = exception
91
- @example = example
92
- @message_color = options.fetch(:message_color) { RSpec.configuration.failure_color }
93
- @description = options.fetch(:description) { example.full_description }
94
- @detail_formatter = options.fetch(:detail_formatter) { Proc.new {} }
95
- @extra_detail_formatter = options.fetch(:extra_detail_formatter) { Proc.new {} }
96
- @backtrace_formatter = options.fetch(:backtrace_formatter) { RSpec.configuration.backtrace_formatter }
97
- @indentation = options.fetch(:indentation, 2)
98
- @skip_shared_group_trace = options.fetch(:skip_shared_group_trace, false)
92
+ def initialize(exception, example, options = {})
93
+ @exception = exception
94
+ @example = example
95
+ @message_color =
96
+ options.fetch(:message_color) do
97
+ RSpec.configuration.failure_color
98
+ end
99
+ @description =
100
+ options.fetch(:description) { example.full_description }
101
+ @detail_formatter = options.fetch(:detail_formatter) { Proc.new {} }
102
+ @extra_detail_formatter =
103
+ options.fetch(:extra_detail_formatter) { Proc.new {} }
104
+ @backtrace_formatter =
105
+ options.fetch(:backtrace_formatter) do
106
+ RSpec.configuration.backtrace_formatter
107
+ end
108
+ @indentation = options.fetch(:indentation, 2)
109
+ @skip_shared_group_trace =
110
+ options.fetch(:skip_shared_group_trace, false)
99
111
  # Patch to convert options[:failure_lines] to groups
100
112
  if options.include?(:failure_lines)
101
113
  @failure_line_groups = [
102
- {
103
- lines: options[:failure_lines],
104
- already_colorized: false
105
- }
114
+ { lines: options[:failure_lines], already_colorized: false }
106
115
  ]
107
116
  end
108
117
  end
109
118
 
110
119
  # Override to only color uncolored lines in red
111
120
  # and to not color empty lines
112
- def colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
113
- lines = failure_line_groups.flat_map do |group|
114
- if group[:already_colorized]
115
- group[:lines]
116
- else
117
- group[:lines].map do |line|
118
- if line.strip.empty?
119
- line
120
- else
121
- indentation = line[/^[ ]+/]
122
- rest = colorizer.wrap(line.sub(/^[ ]+/, ''), message_color)
123
-
124
- if indentation
125
- indentation + rest
121
+ def colorized_message_lines(
122
+ colorizer = ::RSpec::Core::Formatters::ConsoleCodes
123
+ )
124
+ lines =
125
+ failure_line_groups.flat_map do |group|
126
+ if group[:already_colorized]
127
+ group[:lines]
128
+ else
129
+ group[:lines].map do |line|
130
+ if line.strip.empty?
131
+ line
126
132
  else
127
- rest
133
+ indentation = line[/^[ ]+/]
134
+ rest =
135
+ colorizer.wrap(line.sub(/^[ ]+/, ""), message_color)
136
+
137
+ indentation ? indentation + rest : rest
128
138
  end
129
139
  end
130
140
  end
131
141
  end
132
- end
133
142
 
134
143
  add_shared_group_lines(lines, colorizer)
135
144
  end
@@ -158,25 +167,24 @@ module RSpec
158
167
  @failure_line_groups
159
168
  else
160
169
  @failure_line_groups = [
161
- {
162
- lines: failure_slash_error_lines,
163
- already_colorized: true
164
- }
170
+ { lines: failure_slash_error_lines, already_colorized: true }
165
171
  ]
166
172
 
167
173
  sections = [failure_slash_error_lines, exception_lines]
168
- separate_groups = (
169
- sections.any? { |section| section.size > 1 } &&
170
- !exception_lines.first.empty?
171
- )
174
+ separate_groups =
175
+ (
176
+ sections.any? { |section| section.size > 1 } &&
177
+ !exception_lines.first.empty?
178
+ )
172
179
 
173
180
  if separate_groups
174
- @failure_line_groups << { lines: [''], already_colorized: true }
181
+ @failure_line_groups << { lines: [""], already_colorized: true }
175
182
  end
176
183
 
177
- already_colorized = exception_lines.any? do |line|
178
- SuperDiff::Csi.already_colorized?(line)
179
- end
184
+ already_colorized =
185
+ exception_lines.any? do |line|
186
+ SuperDiff::Csi.already_colorized?(line)
187
+ end
180
188
 
181
189
  if already_colorized
182
190
  @failure_line_groups << {
@@ -225,9 +233,8 @@ module RSpec
225
233
  lines[0] = failure_slash_error + lines[0].strip
226
234
  else
227
235
  least_indentation = SnippetExtractor.least_indentation_from(lines)
228
- lines = lines.map do |line|
229
- line.sub(/^#{least_indentation}/, ' ')
230
- end
236
+ lines =
237
+ lines.map { |line| line.sub(/^#{least_indentation}/, " ") }
231
238
  lines.unshift(failure_slash_error)
232
239
  end
233
240
 
@@ -243,7 +250,8 @@ module RSpec
243
250
  exception_backtrace.find do |line|
244
251
  next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])
245
252
  path = File.expand_path(line_path)
246
- path != __FILE__ && (loaded_spec_files.include?(path) || path =~ line_regex)
253
+ path != __FILE__ &&
254
+ (loaded_spec_files.include?(path) || path =~ line_regex)
247
255
  end || exception_backtrace.first
248
256
  end
249
257
  end
@@ -286,36 +294,38 @@ module RSpec
286
294
  def from(expected)
287
295
  return expected if self === expected
288
296
 
289
- text =
290
- colorizer.wrap("Diff:", SuperDiff.configuration.header_color) +
291
- "\n\n" +
292
- colorizer.wrap(
293
- " (Key) ──────────────────────────┐",
294
- SuperDiff.configuration.border_color
295
- ) +
296
- "\n" +
297
- colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
298
- colorizer.wrap(
299
- "‹-› in expected, not in actual",
300
- SuperDiff.configuration.expected_color
301
- ) +
302
- colorizer.wrap(" │", SuperDiff.configuration.border_color) +
303
- "\n" +
304
- colorizer.wrap("", SuperDiff.configuration.border_color) +
305
- colorizer.wrap(
306
- "‹+› in actual, not in expected",
307
- SuperDiff.configuration.actual_color
308
- ) +
309
- colorizer.wrap(" │", SuperDiff.configuration.border_color) +
310
- "\n" +
311
- colorizer.wrap("", SuperDiff.configuration.border_color) +
312
- " in both expected and actual" +
313
- colorizer.wrap(" ", SuperDiff.configuration.border_color) +
314
- "\n" +
315
- colorizer.wrap(
316
- "└─────────────────────────────────┘",
317
- SuperDiff.configuration.border_color
318
- )
297
+ text = colorizer.wrap("Diff:", SuperDiff.configuration.header_color)
298
+
299
+ if SuperDiff.configuration.key_enabled?
300
+ text +=
301
+ "\n\n" +
302
+ colorizer.wrap(
303
+ "┌ (Key) ──────────────────────────┐",
304
+ SuperDiff.configuration.border_color
305
+ ) + "\n" +
306
+ colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
307
+ colorizer.wrap(
308
+ "‹-› in expected, not in actual",
309
+ SuperDiff.configuration.expected_color
310
+ ) +
311
+ colorizer.wrap("", SuperDiff.configuration.border_color) +
312
+ "\n" +
313
+ colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
314
+ colorizer.wrap(
315
+ "‹+› in actual, not in expected",
316
+ SuperDiff.configuration.actual_color
317
+ ) +
318
+ colorizer.wrap("", SuperDiff.configuration.border_color) +
319
+ "\n" +
320
+ colorizer.wrap(" ", SuperDiff.configuration.border_color) +
321
+ " › in both expected and actual" +
322
+ colorizer.wrap("", SuperDiff.configuration.border_color) +
323
+ "\n" +
324
+ colorizer.wrap(
325
+ "└─────────────────────────────────┘",
326
+ SuperDiff.configuration.border_color
327
+ )
328
+ end
319
329
 
320
330
  new([[expected, text]])
321
331
  end
@@ -330,22 +340,21 @@ module RSpec
330
340
  def message_with_diff(message, differ, actual)
331
341
  diff = diffs(differ, actual)
332
342
 
333
- if diff.empty?
334
- message
335
- else
336
- "#{message.rstrip}\n\n#{diff}"
337
- end
343
+ diff.empty? ? message : "#{message.rstrip}\n\n#{diff}"
338
344
  end
339
345
 
340
346
  private
341
347
 
342
348
  # Add extra line breaks in between diffs, and colorize the word "Diff"
343
349
  def diffs(differ, actual)
344
- @expected_list.map do |(expected, diff_label)|
345
- diff = differ.diff(actual, expected)
346
- next if diff.strip.empty?
347
- diff_label + diff
348
- end.compact.join("\n\n")
350
+ @expected_list
351
+ .map do |(expected, diff_label)|
352
+ diff = differ.diff(actual, expected)
353
+ next if diff.strip.empty?
354
+ diff_label + diff
355
+ end
356
+ .compact
357
+ .join("\n\n")
349
358
  end
350
359
  end
351
360
  end
@@ -366,7 +375,7 @@ module RSpec
366
375
 
367
376
  SuperDiff.insert_overrides(self) do
368
377
  def expected_action_for_matcher_text
369
- if [:==, :===, :=~].include?(@operator)
378
+ if %i[== === =~].include?(@operator)
370
379
  "#{@operator}"
371
380
  else
372
381
  "be #{@operator}"
@@ -415,7 +424,7 @@ module RSpec
415
424
  if SuperDiff::RSpec.rspec_version < "3.10"
416
425
  expected
417
426
  else
418
- predicate.to_s.chomp('?')
427
+ predicate.to_s.chomp("?")
419
428
  end
420
429
  end
421
430
 
@@ -507,7 +516,7 @@ module RSpec
507
516
 
508
517
  # Override to use (...) as delimiters rather than {...}
509
518
  def expected_for_matcher_text
510
- super.sub(/^\{ /, '(').gsub(/ \}$/, ')')
519
+ super.sub(/^\{ /, "(").gsub(/ \}$/, ")")
511
520
  end
512
521
 
513
522
  # Override so that the differ knows that this is a partial object
@@ -538,14 +547,17 @@ module RSpec
538
547
  # Override this method to skip non-existent attributes, and to use
539
548
  # public_send
540
549
  def cache_all_values
541
- @values = @expected.keys.inject({}) do |hash, attribute_key|
542
- if @actual.respond_to?(attribute_key)
543
- actual_value = @actual.public_send(attribute_key)
544
- hash.merge(attribute_key => actual_value)
545
- else
546
- hash
547
- end
548
- end
550
+ @values =
551
+ @expected
552
+ .keys
553
+ .inject({}) do |hash, attribute_key|
554
+ if @actual.respond_to?(attribute_key)
555
+ actual_value = @actual.public_send(attribute_key)
556
+ hash.merge(attribute_key => actual_value)
557
+ else
558
+ hash
559
+ end
560
+ end
549
561
  end
550
562
 
551
563
  def actual_has_attribute?(attribute_key, attribute_value)
@@ -624,7 +636,8 @@ module RSpec
624
636
  if actual.respond_to?(:include?)
625
637
  message
626
638
  elsif message.end_with?(".")
627
- message.sub("\.$", ", ") + "but it does not respond to `include?`."
639
+ message.sub("\.$", ", ") +
640
+ "but it does not respond to `include?`."
628
641
  else
629
642
  message + "\n\nBut it does not respond to `include?`."
630
643
  end
@@ -649,9 +662,10 @@ module RSpec
649
662
  # Update to use (...) as delimiter instead of {...}
650
663
  def readable_list_of(items)
651
664
  if items && items.all? { |item| item.is_a?(Hash) }
652
- description_of(items.inject(:merge)).
653
- sub(/^\{ /, '(').
654
- sub(/ \}$/, ')')
665
+ description_of(items.inject(:merge)).sub(/^\{ /, "(").sub(
666
+ / \}$/,
667
+ ")"
668
+ )
655
669
  else
656
670
  super
657
671
  end
@@ -694,9 +708,7 @@ module RSpec
694
708
  end
695
709
 
696
710
  def actual_for_diff
697
- if @actual_error
698
- @actual_error.message
699
- end
711
+ @actual_error.message if @actual_error
700
712
  end
701
713
 
702
714
  def expected_for_matcher_text
@@ -718,11 +730,7 @@ module RSpec
718
730
  end
719
731
 
720
732
  def expected_action_for_failure_message
721
- if @actual_error
722
- "match"
723
- else
724
- "raise error"
725
- end
733
+ @actual_error ? "match" : "raise error"
726
734
  end
727
735
 
728
736
  def matcher_text_builder_class
@@ -770,9 +778,7 @@ module RSpec
770
778
 
771
779
  SuperDiff.insert_overrides(self) do
772
780
  def self.prepended(base)
773
- base.class_eval do
774
- alias_matcher :an_array_matching, :match_array
775
- end
781
+ base.class_eval { alias_matcher :an_array_matching, :match_array }
776
782
  end
777
783
 
778
784
  def match_array(items)
@@ -4,7 +4,8 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  class CollectionIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
- SuperDiff::RSpec.a_collection_including_something?(value) || SuperDiff::RSpec.array_including_something?(value)
7
+ SuperDiff::RSpec.a_collection_including_something?(value) ||
8
+ SuperDiff::RSpec.array_including_something?(value)
8
9
  end
9
10
 
10
11
  def call
@@ -14,11 +15,12 @@ module SuperDiff
14
15
  end
15
16
 
16
17
  nested do |value|
17
- array = if SuperDiff::RSpec.a_collection_including_something?(value)
18
- value.expecteds
19
- else
20
- value.instance_variable_get(:@expected)
21
- end
18
+ array =
19
+ if SuperDiff::RSpec.a_collection_including_something?(value)
20
+ value.expecteds
21
+ else
22
+ value.instance_variable_get(:@expected)
23
+ end
22
24
  insert_array_inspection_of(array)
23
25
  end
24
26
 
@@ -31,23 +31,17 @@ module SuperDiff
31
31
  "#<#{inspected_class} #{inspected_name}"
32
32
  end
33
33
 
34
- when_rendering_to_lines do
35
- add_text " {"
36
- end
34
+ when_rendering_to_lines { add_text " {" }
37
35
  end
38
36
 
39
- when_rendering_to_string do
40
- add_text " "
41
- end
37
+ when_rendering_to_string { add_text " " }
42
38
 
43
39
  nested do |object|
44
40
  insert_hash_inspection_of(builder.doubled_methods)
45
41
  end
46
42
 
47
43
  as_lines_when_rendering_to_lines(collection_bookend: :close) do
48
- when_rendering_to_lines do
49
- add_text "}"
50
- end
44
+ when_rendering_to_lines { add_text "}" }
51
45
 
52
46
  add_text ">"
53
47
  end
@@ -85,16 +79,17 @@ module SuperDiff
85
79
  end
86
80
 
87
81
  def doubled_methods
88
- @_doubled_methods ||= doubled_method_names.reduce({}) do |hash, key|
89
- hash.merge(key => object.public_send(key))
90
- end
82
+ @_doubled_methods ||=
83
+ doubled_method_names.reduce({}) do |hash, key|
84
+ hash.merge(key => object.public_send(key))
85
+ end
91
86
  end
92
87
 
93
88
  def doubled_method_names
94
- object.
95
- __send__(:__mock_proxy).
96
- instance_variable_get("@method_doubles").
97
- keys
89
+ object
90
+ .__send__(:__mock_proxy)
91
+ .instance_variable_get("@method_doubles")
92
+ .keys
98
93
  end
99
94
  end
100
95
  end
@@ -4,7 +4,8 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  class HashIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
- SuperDiff::RSpec.a_hash_including_something?(value) || SuperDiff::RSpec.hash_including_something?(value)
7
+ SuperDiff::RSpec.a_hash_including_something?(value) ||
8
+ SuperDiff::RSpec.hash_including_something?(value)
8
9
  end
9
10
 
10
11
  def call
@@ -4,17 +4,19 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  class InstanceOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
- SuperDiff::RSpec.an_instance_of_something?(value) || SuperDiff::RSpec.instance_of_something?(value)
7
+ SuperDiff::RSpec.an_instance_of_something?(value) ||
8
+ SuperDiff::RSpec.instance_of_something?(value)
8
9
  end
9
10
 
10
11
  def call
11
12
  SuperDiff::ObjectInspection::InspectionTree.new do
12
13
  add_text do |value|
13
- klass = if SuperDiff::RSpec.an_instance_of_something?(value)
14
- value.expected
15
- else
16
- value.instance_variable_get(:@klass)
17
- end
14
+ klass =
15
+ if SuperDiff::RSpec.an_instance_of_something?(value)
16
+ value.expected
17
+ else
18
+ value.instance_variable_get(:@klass)
19
+ end
18
20
  "#<an instance of #{klass}>"
19
21
  end
20
22
  end
@@ -4,17 +4,19 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  class KindOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
6
6
  def self.applies_to?(value)
7
- SuperDiff::RSpec.a_kind_of_something?(value) || SuperDiff::RSpec.kind_of_something?(value)
7
+ SuperDiff::RSpec.a_kind_of_something?(value) ||
8
+ SuperDiff::RSpec.kind_of_something?(value)
8
9
  end
9
10
 
10
11
  def call
11
12
  SuperDiff::ObjectInspection::InspectionTree.new do
12
13
  add_text do |value|
13
- klass = if SuperDiff::RSpec.a_kind_of_something?(value)
14
- value.expected
15
- else
16
- value.instance_variable_get(:@klass)
17
- end
14
+ klass =
15
+ if SuperDiff::RSpec.a_kind_of_something?(value)
16
+ value.expected
17
+ else
18
+ value.instance_variable_get(:@klass)
19
+ end
18
20
  "#<a kind of #{klass}>"
19
21
  end
20
22
  end
@@ -4,39 +4,39 @@ module SuperDiff
4
4
  module InspectionTreeBuilders
5
5
  autoload(
6
6
  :CollectionContainingExactly,
7
- "super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly",
7
+ "super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly"
8
8
  )
9
9
  autoload(
10
10
  :CollectionIncluding,
11
- "super_diff/rspec/object_inspection/inspection_tree_builders/collection_including",
11
+ "super_diff/rspec/object_inspection/inspection_tree_builders/collection_including"
12
12
  )
13
13
  autoload(
14
14
  :Double,
15
- "super_diff/rspec/object_inspection/inspection_tree_builders/double",
15
+ "super_diff/rspec/object_inspection/inspection_tree_builders/double"
16
16
  )
17
17
  autoload(
18
18
  :HashIncluding,
19
- "super_diff/rspec/object_inspection/inspection_tree_builders/hash_including",
19
+ "super_diff/rspec/object_inspection/inspection_tree_builders/hash_including"
20
20
  )
21
21
  autoload(
22
22
  :InstanceOf,
23
- "super_diff/rspec/object_inspection/inspection_tree_builders/instance_of",
23
+ "super_diff/rspec/object_inspection/inspection_tree_builders/instance_of"
24
24
  )
25
25
  autoload(
26
26
  :KindOf,
27
- "super_diff/rspec/object_inspection/inspection_tree_builders/kind_of",
27
+ "super_diff/rspec/object_inspection/inspection_tree_builders/kind_of"
28
28
  )
29
29
  autoload(
30
30
  :ObjectHavingAttributes,
31
- "super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes",
31
+ "super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes"
32
32
  )
33
33
  autoload(
34
34
  :Primitive,
35
- "super_diff/rspec/object_inspection/inspection_tree_builders/primitive",
35
+ "super_diff/rspec/object_inspection/inspection_tree_builders/primitive"
36
36
  )
37
37
  autoload(
38
38
  :ValueWithin,
39
- "super_diff/rspec/object_inspection/inspection_tree_builders/value_within",
39
+ "super_diff/rspec/object_inspection/inspection_tree_builders/value_within"
40
40
  )
41
41
  end
42
42
  end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module ObjectInspection
4
4
  autoload(
5
5
  :InspectionTreeBuilders,
6
- "super_diff/rspec/object_inspection/inspection_tree_builders",
6
+ "super_diff/rspec/object_inspection/inspection_tree_builders"
7
7
  )
8
8
  end
9
9
  end
@@ -3,8 +3,9 @@ module SuperDiff
3
3
  module OperationTreeBuilders
4
4
  class CollectionContainingExactly < SuperDiff::OperationTreeBuilders::Base
5
5
  def self.applies_to?(expected, actual)
6
- SuperDiff::RSpec.a_collection_containing_exactly_something?(expected) &&
7
- actual.is_a?(::Array)
6
+ SuperDiff::RSpec.a_collection_containing_exactly_something?(
7
+ expected
8
+ ) && actual.is_a?(::Array)
8
9
  end
9
10
 
10
11
  def initialize(actual:, **)
@@ -17,11 +18,11 @@ module SuperDiff
17
18
  def unary_operations
18
19
  operations = []
19
20
 
20
- (0...actual.length).reject do |index|
21
- indexes_in_actual_but_not_in_expected.include?(index)
22
- end.each do |index|
23
- add_noop_to(operations, index)
24
- end
21
+ (0...actual.length)
22
+ .reject do |index|
23
+ indexes_in_actual_but_not_in_expected.include?(index)
24
+ end
25
+ .each { |index| add_noop_to(operations, index) }
25
26
 
26
27
  indexes_in_actual_but_not_in_expected.each do |index|
27
28
  add_insert_to(operations, index)
@@ -51,7 +52,7 @@ module SuperDiff
51
52
  collection: collection,
52
53
  key: index,
53
54
  value: value,
54
- index: index,
55
+ index: index
55
56
  )
56
57
  end
57
58
 
@@ -62,7 +63,7 @@ module SuperDiff
62
63
  collection: collection,
63
64
  key: index,
64
65
  value: value,
65
- index: index,
66
+ index: index
66
67
  )
67
68
  end
68
69
 
@@ -73,7 +74,7 @@ module SuperDiff
73
74
  collection: collection,
74
75
  key: index,
75
76
  value: value,
76
- index: index,
77
+ index: index
77
78
  )
78
79
  end
79
80