super_diff 0.6.2 → 0.9.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 +0 -1
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +81 -8
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/csi.rb +1 -2
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +2 -2
- data/lib/super_diff/equality_matchers/default.rb +2 -2
- data/lib/super_diff/equality_matchers/hash.rb +2 -2
- data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
- data/lib/super_diff/equality_matchers/primitive.rb +4 -7
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/helpers.rb +56 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection.rb +12 -1
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/monkey_patches.rb +2 -2
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/rspec.rb +34 -13
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +28 -6
- data/spec/examples.txt +482 -403
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
- data/spec/integration/rspec/eq_matcher_spec.rb +33 -87
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +17 -8
- data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
- data/spec/integration/rspec/match_matcher_spec.rb +93 -5
- data/spec/spec_helper.rb +4 -1
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +2 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
- data/spec/support/integration/test_programs/base.rb +36 -10
- data/spec/support/shared_examples/active_record.rb +3 -2
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +16 -16
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/tmp/warnings_logger/all_warnings.txt +2 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +55 -75
- data/spec/unit/helpers_spec.rb +75 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1530 -800
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- metadata +91 -52
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/spec/combustion/Gemfile.lock +0 -173
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
@@ -0,0 +1,20 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTreeFlatteners
|
3
|
+
autoload :Array, "super_diff/operation_tree_flatteners/array"
|
4
|
+
autoload :Base, "super_diff/operation_tree_flatteners/base"
|
5
|
+
autoload :Collection, "super_diff/operation_tree_flatteners/collection"
|
6
|
+
autoload(
|
7
|
+
:CustomObject,
|
8
|
+
"super_diff/operation_tree_flatteners/custom_object",
|
9
|
+
)
|
10
|
+
autoload(
|
11
|
+
:DefaultObject,
|
12
|
+
"super_diff/operation_tree_flatteners/default_object",
|
13
|
+
)
|
14
|
+
autoload :Hash, "super_diff/operation_tree_flatteners/hash"
|
15
|
+
autoload(
|
16
|
+
:MultilineString,
|
17
|
+
"super_diff/operation_tree_flatteners/multiline_string",
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
@@ -5,13 +5,10 @@ module SuperDiff
|
|
5
5
|
value.is_a?(::Array)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
add_comma: add_comma,
|
14
|
-
)
|
8
|
+
protected
|
9
|
+
|
10
|
+
def operation_tree_flattener_class
|
11
|
+
OperationTreeFlatteners::Array
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -1,33 +1,56 @@
|
|
1
|
-
require
|
1
|
+
require "forwardable"
|
2
2
|
|
3
3
|
module SuperDiff
|
4
4
|
module OperationTrees
|
5
|
-
class Base
|
6
|
-
def self.applies_to?(
|
5
|
+
class Base
|
6
|
+
def self.applies_to?(*)
|
7
7
|
unimplemented_class_method!
|
8
8
|
end
|
9
9
|
|
10
|
+
include Enumerable
|
11
|
+
include ImplementationChecks
|
10
12
|
extend ImplementationChecks
|
13
|
+
extend Forwardable
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
def_delegators :operations, :<<, :delete, :each
|
16
|
+
|
17
|
+
def initialize(operations)
|
18
|
+
@operations = operations
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_diff(indentation_level:)
|
22
|
+
TieredLinesFormatter.call(
|
23
|
+
perhaps_elide(flatten(indentation_level: indentation_level)),
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def flatten(indentation_level:)
|
28
|
+
operation_tree_flattener_class.call(
|
29
|
+
self,
|
30
|
+
indentation_level: indentation_level,
|
31
|
+
)
|
15
32
|
end
|
16
|
-
# rubocop:enable Lint/UnusedMethodArgument
|
17
33
|
|
18
34
|
def pretty_print(pp)
|
19
|
-
pp.
|
20
|
-
|
21
|
-
pp.
|
22
|
-
pp.
|
23
|
-
pp.seplist(self) do |value|
|
24
|
-
pp.pp value
|
25
|
-
end
|
35
|
+
pp.group(1, "#<#{self.class.name} [", "]>") do
|
36
|
+
pp.breakable
|
37
|
+
pp.seplist(self) do |value|
|
38
|
+
pp.pp value
|
26
39
|
end
|
27
40
|
end
|
28
|
-
pp.breakable
|
29
|
-
pp.text("])")
|
30
41
|
end
|
42
|
+
|
43
|
+
def perhaps_elide(tiered_lines)
|
44
|
+
if SuperDiff.configuration.diff_elision_enabled?
|
45
|
+
TieredLinesElider.call(tiered_lines)
|
46
|
+
else
|
47
|
+
tiered_lines
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
attr_reader :operations
|
31
54
|
end
|
32
55
|
end
|
33
56
|
end
|
@@ -5,14 +5,10 @@ module SuperDiff
|
|
5
5
|
value.respond_to?(:attributes_for_super_diff)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
add_comma: add_comma,
|
14
|
-
value_class: value_class,
|
15
|
-
)
|
8
|
+
protected
|
9
|
+
|
10
|
+
def operation_tree_flattener_class
|
11
|
+
OperationTreeFlatteners::CustomObject
|
16
12
|
end
|
17
13
|
end
|
18
14
|
end
|
@@ -1,26 +1,41 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module OperationTrees
|
3
3
|
class DefaultObject < Base
|
4
|
-
def self.applies_to?(
|
4
|
+
def self.applies_to?(*)
|
5
5
|
true
|
6
6
|
end
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :underlying_object
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def initialize(operations, underlying_object:)
|
11
|
+
super(operations)
|
12
|
+
@underlying_object = underlying_object
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
def pretty_print(pp)
|
16
|
+
pp.text "#<#{self.class.name} "
|
17
|
+
pp.nest(1) do
|
18
|
+
pp.breakable
|
19
|
+
pp.text ":operations=>"
|
20
|
+
pp.group(1, "[", "]") do
|
21
|
+
pp.breakable
|
22
|
+
pp.seplist(self) do |value|
|
23
|
+
pp.pp value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
pp.comma_breakable
|
27
|
+
pp.text ":underlying_object=>"
|
28
|
+
pp.object_address_group underlying_object do
|
29
|
+
# do nothing
|
30
|
+
end
|
31
|
+
end
|
32
|
+
pp.text ">"
|
15
33
|
end
|
16
34
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
add_comma: add_comma,
|
22
|
-
value_class: value_class,
|
23
|
-
)
|
35
|
+
protected
|
36
|
+
|
37
|
+
def operation_tree_flattener_class
|
38
|
+
OperationTreeFlatteners::DefaultObject
|
24
39
|
end
|
25
40
|
end
|
26
41
|
end
|
@@ -5,13 +5,10 @@ module SuperDiff
|
|
5
5
|
value.is_a?(::Hash)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
add_comma: add_comma,
|
14
|
-
)
|
8
|
+
protected
|
9
|
+
|
10
|
+
def operation_tree_flattener_class
|
11
|
+
OperationTreeFlatteners::Hash
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -5,13 +5,10 @@ module SuperDiff
|
|
5
5
|
value.is_a?(::String) && value.is_a?(::String)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
collection_prefix: collection_prefix,
|
13
|
-
add_comma: add_comma,
|
14
|
-
)
|
8
|
+
protected
|
9
|
+
|
10
|
+
def operation_tree_flattener_class
|
11
|
+
OperationTreeFlatteners::MultilineString
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -14,14 +14,9 @@ module SuperDiff
|
|
14
14
|
:right_value!,
|
15
15
|
:left_index!,
|
16
16
|
:right_index!,
|
17
|
-
|
17
|
+
children: [],
|
18
18
|
],
|
19
19
|
)
|
20
|
-
|
21
|
-
def should_add_comma_after_displaying?
|
22
|
-
left_index < left_collection.size - 1 ||
|
23
|
-
right_index < right_collection.size - 1
|
24
|
-
end
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
@@ -1,37 +1,9 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module Operations
|
3
3
|
class UnaryOperation
|
4
|
-
|
5
|
-
:name,
|
6
|
-
:collection,
|
7
|
-
:key,
|
8
|
-
:value,
|
9
|
-
# TODO: Is this even used??
|
10
|
-
:index,
|
11
|
-
:index_in_collection,
|
12
|
-
)
|
4
|
+
extend AttrExtras.mixin
|
13
5
|
|
14
|
-
|
15
|
-
name:,
|
16
|
-
collection:,
|
17
|
-
key:,
|
18
|
-
value:,
|
19
|
-
# TODO: Is this even used??
|
20
|
-
index:,
|
21
|
-
index_in_collection: index
|
22
|
-
)
|
23
|
-
@name = name
|
24
|
-
@collection = collection
|
25
|
-
@key = key
|
26
|
-
@value = value
|
27
|
-
# TODO: Is this even used??
|
28
|
-
@index = index
|
29
|
-
@index_in_collection = index_in_collection
|
30
|
-
end
|
31
|
-
|
32
|
-
def should_add_comma_after_displaying?
|
33
|
-
index_in_collection < collection.size - 1
|
34
|
-
end
|
6
|
+
rattr_initialize [:name!, :collection!, :key!, :value!, :index!]
|
35
7
|
end
|
36
8
|
end
|
37
9
|
end
|
@@ -7,7 +7,7 @@ module SuperDiff
|
|
7
7
|
|
8
8
|
def self.guarding_recursion_of(*objects, &block)
|
9
9
|
already_seen_objects, first_seen_objects = objects.partition do |object|
|
10
|
-
|
10
|
+
!SuperDiff.primitive?(object) && already_seen?(object)
|
11
11
|
end
|
12
12
|
|
13
13
|
first_seen_objects.each do |object|
|
@@ -38,8 +38,8 @@ module SuperDiff
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.
|
42
|
-
already_seen_object_ids.
|
41
|
+
def self.already_seen?(object)
|
42
|
+
already_seen_object_ids.include?(object.object_id)
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.already_seen_object_ids
|
@@ -3,8 +3,10 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class CollectionIncluding < SuperDiff::Differs::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
|
7
|
-
|
6
|
+
(
|
7
|
+
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
8
|
+
SuperDiff::RSpec.array_including_something?(expected)
|
9
|
+
) && actual.is_a?(::Array)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
@@ -3,8 +3,10 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class HashIncluding < SuperDiff::Differs::Hash
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
|
7
|
-
|
6
|
+
(
|
7
|
+
SuperDiff::RSpec.a_hash_including_something?(expected) ||
|
8
|
+
SuperDiff::RSpec.hash_including_something?(expected)
|
9
|
+
) && actual.is_a?(::Hash)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
@@ -266,14 +266,14 @@ module RSpec
|
|
266
266
|
SuperDiff.insert_singleton_overrides(self) do
|
267
267
|
# Override to use our formatting algorithm
|
268
268
|
def format(value)
|
269
|
-
SuperDiff.inspect_object(value,
|
269
|
+
SuperDiff.inspect_object(value, as_lines: false)
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
273
273
|
SuperDiff.insert_overrides(self) do
|
274
274
|
# Override to use our formatting algorithm
|
275
275
|
def format(value)
|
276
|
-
SuperDiff.inspect_object(value,
|
276
|
+
SuperDiff.inspect_object(value, as_lines: false)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
end
|
@@ -1,24 +1,25 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module ObjectInspection
|
4
|
-
module
|
5
|
-
class CollectionContainingExactly < SuperDiff::ObjectInspection::
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class CollectionContainingExactly < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
7
|
SuperDiff::RSpec.a_collection_containing_exactly_something?(value)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def inspection_tree
|
10
|
+
def call
|
13
11
|
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<a collection containing exactly ("
|
14
|
+
end
|
15
15
|
|
16
16
|
nested do |aliased_matcher|
|
17
17
|
insert_array_inspection_of(aliased_matcher.expected)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
21
|
+
add_text ")>"
|
22
|
+
end
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class CollectionIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
SuperDiff::RSpec.a_collection_including_something?(value) || SuperDiff::RSpec.array_including_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<a collection including ("
|
14
|
+
end
|
15
|
+
|
16
|
+
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
|
22
|
+
insert_array_inspection_of(array)
|
23
|
+
end
|
24
|
+
|
25
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
26
|
+
add_text ")>"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class Double < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
value.is_a?(::RSpec::Mocks::Double)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
builder = self
|
12
|
+
empty = -> { empty? }
|
13
|
+
nonempty = -> { !empty? }
|
14
|
+
|
15
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
16
|
+
only_when empty do
|
17
|
+
as_lines_when_rendering_to_lines do
|
18
|
+
add_text do |object|
|
19
|
+
inspected_class = builder.inspected_class
|
20
|
+
inspected_name = builder.inspected_name
|
21
|
+
"#<#{inspected_class} #{inspected_name}>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
only_when nonempty do
|
27
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
28
|
+
add_text do |object|
|
29
|
+
inspected_class = builder.inspected_class
|
30
|
+
inspected_name = builder.inspected_name
|
31
|
+
"#<#{inspected_class} #{inspected_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
when_rendering_to_lines do
|
35
|
+
add_text " {"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
when_rendering_to_string do
|
40
|
+
add_text " "
|
41
|
+
end
|
42
|
+
|
43
|
+
nested do |object|
|
44
|
+
insert_hash_inspection_of(builder.doubled_methods)
|
45
|
+
end
|
46
|
+
|
47
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
48
|
+
when_rendering_to_lines do
|
49
|
+
add_text "}"
|
50
|
+
end
|
51
|
+
|
52
|
+
add_text ">"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def empty?
|
59
|
+
doubled_methods.empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def nonempty?
|
63
|
+
!empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def inspected_class
|
67
|
+
case object
|
68
|
+
when ::RSpec::Mocks::InstanceVerifyingDouble
|
69
|
+
"InstanceDouble"
|
70
|
+
when ::RSpec::Mocks::ClassVerifyingDouble
|
71
|
+
"ClassDouble"
|
72
|
+
when ::RSpec::Mocks::ObjectVerifyingDouble
|
73
|
+
"ObjectDouble"
|
74
|
+
else
|
75
|
+
"Double"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def inspected_name
|
80
|
+
if object.instance_variable_get("@name")
|
81
|
+
object.instance_variable_get("@name").inspect
|
82
|
+
else
|
83
|
+
"(anonymous)"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def doubled_methods
|
88
|
+
@_doubled_methods ||= doubled_method_names.reduce({}) do |hash, key|
|
89
|
+
hash.merge(key => object.public_send(key))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def doubled_method_names
|
94
|
+
object.
|
95
|
+
__send__(:__mock_proxy).
|
96
|
+
instance_variable_get("@method_doubles").
|
97
|
+
keys
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class HashIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
SuperDiff::RSpec.a_hash_including_something?(value) || SuperDiff::RSpec.hash_including_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<a hash including ("
|
14
|
+
end
|
15
|
+
|
16
|
+
nested do |value|
|
17
|
+
hash =
|
18
|
+
if SuperDiff::RSpec.a_hash_including_something?(value)
|
19
|
+
value.expecteds.first
|
20
|
+
else
|
21
|
+
value.instance_variable_get(:@expected)
|
22
|
+
end
|
23
|
+
|
24
|
+
insert_hash_inspection_of(hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
28
|
+
add_text ")>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class InstanceOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
SuperDiff::RSpec.an_instance_of_something?(value) || SuperDiff::RSpec.instance_of_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
+
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
|
18
|
+
"#<an instance of #{klass}>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class KindOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
SuperDiff::RSpec.a_kind_of_something?(value) || SuperDiff::RSpec.kind_of_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
+
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
|
18
|
+
"#<a kind of #{klass}>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,27 +1,25 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module ObjectInspection
|
4
|
-
module
|
5
|
-
class ObjectHavingAttributes < SuperDiff::ObjectInspection::
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class ObjectHavingAttributes < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
7
|
SuperDiff::RSpec.an_object_having_some_attributes?(value)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def inspection_tree
|
10
|
+
def call
|
13
11
|
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
|
12
|
+
as_lines_when_rendering_to_lines(collection_bookend: :open) do
|
13
|
+
add_text "#<an object having attributes ("
|
14
|
+
end
|
15
15
|
|
16
16
|
nested do |aliased_matcher|
|
17
|
-
insert_hash_inspection_of(
|
18
|
-
aliased_matcher.expected,
|
19
|
-
initial_break: nil,
|
20
|
-
)
|
17
|
+
insert_hash_inspection_of(aliased_matcher.expected)
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
20
|
+
as_lines_when_rendering_to_lines(collection_bookend: :close) do
|
21
|
+
add_text ")>"
|
22
|
+
end
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|