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
@@ -9,21 +9,21 @@ module SuperDiff
|
|
9
9
|
type: :noop,
|
10
10
|
indentation_level: indentation_level,
|
11
11
|
value: open_token,
|
12
|
-
collection_bookend: :open
|
12
|
+
collection_bookend: :open
|
13
13
|
),
|
14
14
|
*inner_lines,
|
15
15
|
Line.new(
|
16
16
|
type: :noop,
|
17
17
|
indentation_level: indentation_level,
|
18
18
|
value: close_token,
|
19
|
-
collection_bookend: :close
|
20
|
-
)
|
19
|
+
collection_bookend: :close
|
20
|
+
)
|
21
21
|
]
|
22
22
|
end
|
23
23
|
|
24
24
|
def inner_lines
|
25
|
-
@_inner_lines ||=
|
26
|
-
flat_map do |operation|
|
25
|
+
@_inner_lines ||=
|
26
|
+
operation_tree.flat_map do |operation|
|
27
27
|
lines =
|
28
28
|
if operation.name == :change
|
29
29
|
build_lines_for_change_operation(operation)
|
@@ -33,7 +33,7 @@ module SuperDiff
|
|
33
33
|
|
34
34
|
maybe_add_prefix_at_beginning_of_lines(
|
35
35
|
maybe_add_comma_at_end_of_lines(lines, operation),
|
36
|
-
operation
|
36
|
+
operation
|
37
37
|
)
|
38
38
|
end
|
39
39
|
end
|
@@ -51,8 +51,7 @@ module SuperDiff
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def add_prefix_at_beginning_of_lines(lines, operation)
|
54
|
-
[lines[0].prefixed_with(item_prefix_for(operation))] +
|
55
|
-
lines[1..-1]
|
54
|
+
[lines[0].prefixed_with(item_prefix_for(operation))] + lines[1..-1]
|
56
55
|
end
|
57
56
|
|
58
57
|
def maybe_add_comma_at_end_of_lines(lines, operation)
|
@@ -79,14 +78,12 @@ module SuperDiff
|
|
79
78
|
def build_lines_for_change_operation(operation)
|
80
79
|
SuperDiff::RecursionGuard.guarding_recursion_of(
|
81
80
|
operation.left_collection,
|
82
|
-
operation.right_collection
|
81
|
+
operation.right_collection
|
83
82
|
) do |already_seen|
|
84
83
|
if already_seen
|
85
84
|
raise InfiniteRecursionError
|
86
85
|
else
|
87
|
-
operation.children.flatten(
|
88
|
-
indentation_level: indentation_level + 1,
|
89
|
-
)
|
86
|
+
operation.children.flatten(indentation_level: indentation_level + 1)
|
90
87
|
end
|
91
88
|
end
|
92
89
|
end
|
@@ -99,14 +96,14 @@ module SuperDiff
|
|
99
96
|
Line.new(
|
100
97
|
type: operation.name,
|
101
98
|
indentation_level: indentation_level,
|
102
|
-
value: SuperDiff::RecursionGuard::PLACEHOLDER
|
103
|
-
)
|
99
|
+
value: SuperDiff::RecursionGuard::PLACEHOLDER
|
100
|
+
)
|
104
101
|
]
|
105
102
|
else
|
106
103
|
build_lines_from_inspection_of(
|
107
104
|
operation.value,
|
108
105
|
type: operation.name,
|
109
|
-
indentation_level: indentation_level
|
106
|
+
indentation_level: indentation_level
|
110
107
|
)
|
111
108
|
end
|
112
109
|
end
|
@@ -125,7 +122,7 @@ module SuperDiff
|
|
125
122
|
value,
|
126
123
|
as_lines: true,
|
127
124
|
type: type,
|
128
|
-
indentation_level: indentation_level
|
125
|
+
indentation_level: indentation_level
|
129
126
|
)
|
130
127
|
end
|
131
128
|
|
@@ -14,11 +14,7 @@ module SuperDiff
|
|
14
14
|
def item_prefix_for(operation)
|
15
15
|
key = key_for(operation)
|
16
16
|
|
17
|
-
|
18
|
-
"#{key}: "
|
19
|
-
else
|
20
|
-
"#{key.inspect} => "
|
21
|
-
end
|
17
|
+
format_keys_as_kwargs? ? "#{key}: " : "#{key.inspect} => "
|
22
18
|
end
|
23
19
|
|
24
20
|
private
|
@@ -30,11 +26,7 @@ module SuperDiff
|
|
30
26
|
def key_for(operation)
|
31
27
|
# Note: We could have used the right_key here too, they're both the
|
32
28
|
# same keys
|
33
|
-
|
34
|
-
operation.left_key
|
35
|
-
else
|
36
|
-
operation.key
|
37
|
-
end
|
29
|
+
operation.respond_to?(:left_key) ? operation.left_key : operation.key
|
38
30
|
end
|
39
31
|
end
|
40
32
|
end
|
@@ -8,7 +8,8 @@ module SuperDiff
|
|
8
8
|
indentation_level: indentation_level,
|
9
9
|
# TODO: Test that quotes and things don't get escaped but escape
|
10
10
|
# characters do
|
11
|
-
value:
|
11
|
+
value:
|
12
|
+
operation.value.inspect[1..-2].gsub(/\\"/, '"').gsub(/\\'/, "'")
|
12
13
|
)
|
13
14
|
end
|
14
15
|
end
|
@@ -5,16 +5,16 @@ module SuperDiff
|
|
5
5
|
autoload :Collection, "super_diff/operation_tree_flatteners/collection"
|
6
6
|
autoload(
|
7
7
|
:CustomObject,
|
8
|
-
"super_diff/operation_tree_flatteners/custom_object"
|
8
|
+
"super_diff/operation_tree_flatteners/custom_object"
|
9
9
|
)
|
10
10
|
autoload(
|
11
11
|
:DefaultObject,
|
12
|
-
"super_diff/operation_tree_flatteners/default_object"
|
12
|
+
"super_diff/operation_tree_flatteners/default_object"
|
13
13
|
)
|
14
14
|
autoload :Hash, "super_diff/operation_tree_flatteners/hash"
|
15
15
|
autoload(
|
16
16
|
:MultilineString,
|
17
|
-
"super_diff/operation_tree_flatteners/multiline_string"
|
17
|
+
"super_diff/operation_tree_flatteners/multiline_string"
|
18
18
|
)
|
19
19
|
end
|
20
20
|
end
|
@@ -20,23 +20,21 @@ module SuperDiff
|
|
20
20
|
|
21
21
|
def to_diff(indentation_level:)
|
22
22
|
TieredLinesFormatter.call(
|
23
|
-
perhaps_elide(flatten(indentation_level: indentation_level))
|
23
|
+
perhaps_elide(flatten(indentation_level: indentation_level))
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
27
27
|
def flatten(indentation_level:)
|
28
28
|
operation_tree_flattener_class.call(
|
29
29
|
self,
|
30
|
-
indentation_level: indentation_level
|
30
|
+
indentation_level: indentation_level
|
31
31
|
)
|
32
32
|
end
|
33
33
|
|
34
34
|
def pretty_print(pp)
|
35
35
|
pp.group(1, "#<#{self.class.name} [", "]>") do
|
36
36
|
pp.breakable
|
37
|
-
pp.seplist(self)
|
38
|
-
pp.pp value
|
39
|
-
end
|
37
|
+
pp.seplist(self) { |value| pp.pp value }
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
data/lib/super_diff/rails.rb
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
require "super_diff/
|
1
|
+
require "super_diff/active_support"
|
2
|
+
require "super_diff/active_record" if defined?(ActiveRecord)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "set"
|
2
2
|
|
3
3
|
module SuperDiff
|
4
4
|
module RecursionGuard
|
@@ -6,9 +6,10 @@ module SuperDiff
|
|
6
6
|
PLACEHOLDER = "∙∙∙".freeze
|
7
7
|
|
8
8
|
def self.guarding_recursion_of(*objects, &block)
|
9
|
-
already_seen_objects, first_seen_objects =
|
10
|
-
|
11
|
-
|
9
|
+
already_seen_objects, first_seen_objects =
|
10
|
+
objects.partition do |object|
|
11
|
+
!SuperDiff.primitive?(object) && already_seen?(object)
|
12
|
+
end
|
12
13
|
|
13
14
|
first_seen_objects.each do |object|
|
14
15
|
already_seen_object_ids.add(object.object_id)
|
@@ -43,8 +43,9 @@ module SuperDiff
|
|
43
43
|
actual: actual_for_matcher_text,
|
44
44
|
expected_for_failure_message: expected_for_failure_message,
|
45
45
|
expected_for_description: expected_for_description,
|
46
|
-
expected_action_for_failure_message:
|
47
|
-
|
46
|
+
expected_action_for_failure_message:
|
47
|
+
expected_action_for_failure_message,
|
48
|
+
expected_action_for_description: expected_action_for_description
|
48
49
|
}
|
49
50
|
end
|
50
51
|
|
@@ -84,9 +85,7 @@ module SuperDiff
|
|
84
85
|
|
85
86
|
def matchers
|
86
87
|
Object.new.tap do |object|
|
87
|
-
object.singleton_class.class_eval
|
88
|
-
include ::RSpec::Matchers
|
89
|
-
end
|
88
|
+
object.singleton_class.class_eval { include ::RSpec::Matchers }
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -7,11 +7,8 @@ module SuperDiff
|
|
7
7
|
|
8
8
|
def diff
|
9
9
|
if worth_diffing?
|
10
|
-
diff =
|
11
|
-
expected,
|
12
|
-
actual,
|
13
|
-
omit_empty: true,
|
14
|
-
)
|
10
|
+
diff =
|
11
|
+
SuperDiff::Differs::Main.call(expected, actual, omit_empty: true)
|
15
12
|
"\n\n" + diff
|
16
13
|
else
|
17
14
|
""
|
@@ -23,8 +20,7 @@ module SuperDiff
|
|
23
20
|
private
|
24
21
|
|
25
22
|
def worth_diffing?
|
26
|
-
comparing_inequal_values? &&
|
27
|
-
!comparing_primitive_values? &&
|
23
|
+
comparing_inequal_values? && !comparing_primitive_values? &&
|
28
24
|
!comparing_singleline_strings?
|
29
25
|
end
|
30
26
|
|
@@ -33,16 +29,13 @@ module SuperDiff
|
|
33
29
|
end
|
34
30
|
|
35
31
|
def comparing_primitive_values?
|
36
|
-
expected.is_a?(Symbol) ||
|
37
|
-
expected.is_a?(Integer) ||
|
32
|
+
expected.is_a?(Symbol) || expected.is_a?(Integer) ||
|
38
33
|
[true, false, nil].include?(expected)
|
39
34
|
end
|
40
35
|
|
41
36
|
def comparing_singleline_strings?
|
42
|
-
expected.is_a?(String) &&
|
43
|
-
|
44
|
-
!expected.include?("\n") &&
|
45
|
-
!actual.include?("\n")
|
37
|
+
expected.is_a?(String) && actual.is_a?(String) &&
|
38
|
+
!expected.include?("\n") && !actual.include?("\n")
|
46
39
|
end
|
47
40
|
|
48
41
|
def helpers
|
@@ -3,8 +3,9 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class CollectionContainingExactly < SuperDiff::Differs::Array
|
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
|
private
|
@@ -5,7 +5,7 @@ module SuperDiff
|
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
8
|
-
|
8
|
+
SuperDiff::RSpec.array_including_something?(expected)
|
9
9
|
) && actual.is_a?(::Array)
|
10
10
|
end
|
11
11
|
|
@@ -5,7 +5,7 @@ module SuperDiff
|
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
SuperDiff::RSpec.a_hash_including_something?(expected) ||
|
8
|
-
|
8
|
+
SuperDiff::RSpec.hash_including_something?(expected)
|
9
9
|
) && actual.is_a?(::Hash)
|
10
10
|
end
|
11
11
|
|
@@ -3,16 +3,16 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
autoload(
|
5
5
|
:CollectionContainingExactly,
|
6
|
-
"super_diff/rspec/differs/collection_containing_exactly"
|
6
|
+
"super_diff/rspec/differs/collection_containing_exactly"
|
7
7
|
)
|
8
8
|
autoload(
|
9
9
|
:CollectionIncluding,
|
10
|
-
"super_diff/rspec/differs/collection_including"
|
10
|
+
"super_diff/rspec/differs/collection_including"
|
11
11
|
)
|
12
12
|
autoload :HashIncluding, "super_diff/rspec/differs/hash_including"
|
13
13
|
autoload(
|
14
14
|
:ObjectHavingAttributes,
|
15
|
-
"super_diff/rspec/differs/object_having_attributes"
|
15
|
+
"super_diff/rspec/differs/object_having_attributes"
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
@@ -28,11 +28,12 @@ module SuperDiff
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def matcher_description
|
31
|
-
template =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
template =
|
32
|
+
MatcherTextTemplate.new do |t|
|
33
|
+
t.add_text expected_action_for_description
|
34
|
+
add_expected_value_to_description(t)
|
35
|
+
add_extra_after_expected_to(t)
|
36
|
+
end
|
36
37
|
|
37
38
|
Csi.decolorize(template.to_s(as_single_line: true))
|
38
39
|
end
|
@@ -61,7 +62,7 @@ module SuperDiff
|
|
61
62
|
:expected_for_description,
|
62
63
|
:expected_action_for_failure_message,
|
63
64
|
:expected_action_for_description,
|
64
|
-
:template
|
65
|
+
:template
|
65
66
|
)
|
66
67
|
|
67
68
|
def negated?
|
@@ -111,7 +112,7 @@ module SuperDiff
|
|
111
112
|
template.add_text " "
|
112
113
|
template.add_text_in_color(
|
113
114
|
expected_color,
|
114
|
-
expected_for_failure_message
|
115
|
+
expected_for_failure_message
|
115
116
|
)
|
116
117
|
end
|
117
118
|
end
|
@@ -130,17 +131,14 @@ module SuperDiff
|
|
130
131
|
end
|
131
132
|
|
132
133
|
def to_or_not_to
|
133
|
-
|
134
|
-
"not to"
|
135
|
-
else
|
136
|
-
"to"
|
137
|
-
end
|
134
|
+
negated? ? "not to" : "to"
|
138
135
|
end
|
139
136
|
|
140
137
|
def phrase_width
|
141
|
-
[actual_phrase, expected_phrase].
|
142
|
-
|
143
|
-
|
138
|
+
[actual_phrase, expected_phrase].map do |text|
|
139
|
+
Csi.decolorize(text.to_s).length
|
140
|
+
end
|
141
|
+
.max
|
144
142
|
end
|
145
143
|
|
146
144
|
# TODO: Should this be applied to expected and actual automatically
|
@@ -31,21 +31,19 @@ module SuperDiff
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_actual_value
|
34
|
-
template.add_text_in_color(actual_color)
|
35
|
-
description_of(actual)
|
36
|
-
end
|
34
|
+
template.add_text_in_color(actual_color) { description_of(actual) }
|
37
35
|
end
|
38
36
|
|
39
37
|
def add_expected_value_to_failure_message(template)
|
40
38
|
template.add_text " "
|
41
39
|
template.add_text_in_color(
|
42
40
|
expected_color,
|
43
|
-
"#{expected_for_failure_message}?"
|
41
|
+
"#{expected_for_failure_message}?"
|
44
42
|
)
|
45
43
|
template.add_text " or "
|
46
44
|
template.add_text_in_color(
|
47
45
|
expected_color,
|
48
|
-
"#{expected_for_failure_message}s?"
|
46
|
+
"#{expected_for_failure_message}s?"
|
49
47
|
)
|
50
48
|
end
|
51
49
|
|
@@ -53,12 +51,12 @@ module SuperDiff
|
|
53
51
|
template.add_text " "
|
54
52
|
template.add_text_in_color(
|
55
53
|
expected_color,
|
56
|
-
"`#{expected_for_description}?`"
|
54
|
+
"`#{expected_for_description}?`"
|
57
55
|
)
|
58
56
|
template.add_text " or "
|
59
57
|
template.add_text_in_color(
|
60
58
|
expected_color,
|
61
|
-
"`#{expected_for_description}s?`"
|
59
|
+
"`#{expected_for_description}s?`"
|
62
60
|
)
|
63
61
|
end
|
64
62
|
|
@@ -25,16 +25,14 @@ module SuperDiff
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def add_actual_value
|
28
|
-
template.add_text_in_color(actual_color)
|
29
|
-
description_of(actual)
|
30
|
-
end
|
28
|
+
template.add_text_in_color(actual_color) { description_of(actual) }
|
31
29
|
end
|
32
30
|
|
33
31
|
def add_expected_value_to_failure_message(template)
|
34
32
|
template.add_text " "
|
35
33
|
template.add_text_in_color(
|
36
34
|
expected_color,
|
37
|
-
expected_for_failure_message
|
35
|
+
expected_for_failure_message
|
38
36
|
)
|
39
37
|
end
|
40
38
|
|
@@ -42,7 +40,7 @@ module SuperDiff
|
|
42
40
|
template.add_text " "
|
43
41
|
template.add_text_in_color(
|
44
42
|
expected_color,
|
45
|
-
"`#{expected_for_description}`"
|
43
|
+
"`#{expected_for_description}`"
|
46
44
|
)
|
47
45
|
end
|
48
46
|
|
@@ -24,9 +24,7 @@ module SuperDiff
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def add_extra_after_expected_to(template)
|
27
|
-
if expected_arity
|
28
|
-
add_arity_clause_to(template)
|
29
|
-
end
|
27
|
+
add_arity_clause_to(template) if expected_arity
|
30
28
|
|
31
29
|
if arbitrary_keywords?
|
32
30
|
add_arbitrary_keywords_clause_to(template)
|
@@ -34,9 +32,7 @@ module SuperDiff
|
|
34
32
|
add_keywords_clause_to(template)
|
35
33
|
end
|
36
34
|
|
37
|
-
if unlimited_arguments?
|
38
|
-
add_unlimited_arguments_clause_to(template)
|
39
|
-
end
|
35
|
+
add_unlimited_arguments_clause_to(template) if unlimited_arguments?
|
40
36
|
end
|
41
37
|
|
42
38
|
private
|
@@ -4,25 +4,22 @@ module SuperDiff
|
|
4
4
|
autoload :Base, "super_diff/rspec/matcher_text_builders/base"
|
5
5
|
autoload(
|
6
6
|
:BePredicate,
|
7
|
-
"super_diff/rspec/matcher_text_builders/be_predicate"
|
7
|
+
"super_diff/rspec/matcher_text_builders/be_predicate"
|
8
8
|
)
|
9
9
|
autoload(
|
10
10
|
:ContainExactly,
|
11
|
-
"super_diff/rspec/matcher_text_builders/contain_exactly"
|
11
|
+
"super_diff/rspec/matcher_text_builders/contain_exactly"
|
12
12
|
)
|
13
13
|
autoload(
|
14
14
|
:HavePredicate,
|
15
|
-
"super_diff/rspec/matcher_text_builders/have_predicate"
|
15
|
+
"super_diff/rspec/matcher_text_builders/have_predicate"
|
16
16
|
)
|
17
17
|
autoload :Match, "super_diff/rspec/matcher_text_builders/match"
|
18
18
|
autoload(
|
19
19
|
:RaiseError,
|
20
|
-
"super_diff/rspec/matcher_text_builders/raise_error"
|
21
|
-
)
|
22
|
-
autoload(
|
23
|
-
:RespondTo,
|
24
|
-
"super_diff/rspec/matcher_text_builders/respond_to",
|
20
|
+
"super_diff/rspec/matcher_text_builders/raise_error"
|
25
21
|
)
|
22
|
+
autoload(:RespondTo, "super_diff/rspec/matcher_text_builders/respond_to")
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -10,9 +10,7 @@ module SuperDiff
|
|
10
10
|
def initialize
|
11
11
|
@tokens = []
|
12
12
|
|
13
|
-
if block_given?
|
14
|
-
yield self
|
15
|
-
end
|
13
|
+
yield self if block_given?
|
16
14
|
end
|
17
15
|
|
18
16
|
def add_text(*args, &block)
|
@@ -44,16 +42,15 @@ module SuperDiff
|
|
44
42
|
end
|
45
43
|
|
46
44
|
def length_of_first_paragraph
|
47
|
-
Csi.decolorize(to_string_in_singleline_mode).
|
48
|
-
split(/\n\n/).
|
49
|
-
first.
|
50
|
-
length
|
45
|
+
Csi.decolorize(to_string_in_singleline_mode).split(/\n\n/).first.length
|
51
46
|
end
|
52
47
|
|
53
48
|
def to_s(as_single_line: nil)
|
54
|
-
if length_of_first_paragraph > MAX_LINE_LENGTH ||
|
49
|
+
if length_of_first_paragraph > MAX_LINE_LENGTH ||
|
50
|
+
as_single_line == false
|
55
51
|
to_string_in_multiline_mode
|
56
|
-
elsif length_of_first_paragraph <= MAX_LINE_LENGTH ||
|
52
|
+
elsif length_of_first_paragraph <= MAX_LINE_LENGTH ||
|
53
|
+
as_single_line == true
|
57
54
|
to_string_in_singleline_mode
|
58
55
|
end
|
59
56
|
end
|
@@ -77,14 +74,14 @@ module SuperDiff
|
|
77
74
|
class Base
|
78
75
|
def to_string_in_singleline_mode
|
79
76
|
raise NotImplementedError.new(
|
80
|
-
|
81
|
-
|
77
|
+
"#{self.class} must support #to_string_in_singleline_mode"
|
78
|
+
)
|
82
79
|
end
|
83
80
|
|
84
81
|
def to_string_in_multiline_mode
|
85
82
|
raise NotImplementedError.new(
|
86
|
-
|
87
|
-
|
83
|
+
"#{self.class} must support #to_string_in_multiline_mode"
|
84
|
+
)
|
88
85
|
end
|
89
86
|
|
90
87
|
def length
|
@@ -117,8 +114,8 @@ module SuperDiff
|
|
117
114
|
def evaluate
|
118
115
|
if immediate_value && block
|
119
116
|
raise ArgumentError.new(
|
120
|
-
|
121
|
-
|
117
|
+
"Cannot provide both immediate value and block"
|
118
|
+
)
|
122
119
|
end
|
123
120
|
|
124
121
|
immediate_value || block.call
|
@@ -186,7 +183,7 @@ module SuperDiff
|
|
186
183
|
evaluate.map do |value|
|
187
184
|
colorizer.wrap(
|
188
185
|
::RSpec::Support::ObjectFormatter.format(value),
|
189
|
-
color
|
186
|
+
color
|
190
187
|
)
|
191
188
|
end
|
192
189
|
end
|