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.
- checksums.yaml +4 -4
- data/README.md +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +5 -13
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +1 -3
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +3 -9
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -11
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +1 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +3 -3
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +46 -60
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +2 -6
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +3 -9
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +5 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +4 -12
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +6 -23
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +8 -20
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +1 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -5
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +122 -116
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +11 -16
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +2 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +8 -6
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +9 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +11 -13
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +4 -9
- data/spec/examples.txt +493 -485
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +20 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +242 -239
- data/spec/integration/rspec/eq_matcher_spec.rb +595 -557
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +294 -286
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +317 -215
- data/spec/integration/rspec/match_array_matcher_spec.rb +276 -273
- data/spec/integration/rspec/match_matcher_spec.rb +847 -834
- data/spec/integration/rspec/raise_error_matcher_spec.rb +468 -453
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/spec_helper.rb +17 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +35 -28
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/test_programs/base.rb +12 -17
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +30 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +232 -214
- data/spec/support/shared_examples/active_support.rb +53 -51
- data/spec/support/shared_examples/elided_diffs.rb +405 -381
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +424 -388
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +5 -5
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection_spec.rb +349 -324
- data/spec/unit/super_diff_spec.rb +1542 -1449
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +73 -73
- 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?(
|
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(
|
68
|
+
RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.fetch(
|
67
69
|
code_or_symbol
|
68
|
-
|
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
|
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
|
91
|
-
@example
|
92
|
-
@message_color
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@
|
97
|
-
|
98
|
-
@
|
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(
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
group[:
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
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
|
-
|
170
|
-
|
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: [
|
181
|
+
@failure_line_groups << { lines: [""], already_colorized: true }
|
175
182
|
end
|
176
183
|
|
177
|
-
already_colorized =
|
178
|
-
|
179
|
-
|
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 =
|
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__ &&
|
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
|
-
|
291
|
-
|
292
|
-
|
293
|
-
"
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
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
|
-
|
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
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
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 [
|
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(/^\{ /,
|
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 =
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
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("\.$", ", ") +
|
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
|
-
|
654
|
-
|
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
|
-
|
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
|
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)
|
data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb
CHANGED
@@ -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) ||
|
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 =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
35
|
-
add_text " {"
|
36
|
-
end
|
34
|
+
when_rendering_to_lines { add_text " {" }
|
37
35
|
end
|
38
36
|
|
39
|
-
when_rendering_to_string
|
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
|
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 ||=
|
89
|
-
|
90
|
-
|
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) ||
|
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) ||
|
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 =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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) ||
|
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 =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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,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?(
|
7
|
-
|
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)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
|