super_diff 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +24 -12
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +15 -6
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +23 -8
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +4 -0
- data/lib/super_diff/active_support.rb +2 -1
- data/lib/super_diff/differs/date_like.rb +15 -0
- data/lib/super_diff/differs/defaults.rb +1 -0
- data/lib/super_diff/differs.rb +1 -0
- data/lib/super_diff/errors.rb +0 -4
- data/lib/super_diff/object_inspection/inspection_tree.rb +25 -20
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +31 -12
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +19 -9
- data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +46 -21
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +39 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +31 -20
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +4 -0
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +3 -2
- data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders.rb +1 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
- data/lib/super_diff/rspec/monkey_patches.rb +59 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +19 -13
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +30 -26
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +19 -14
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +9 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +9 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +4 -0
- data/lib/super_diff/rspec.rb +10 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +9 -0
- data/spec/examples.txt +543 -493
- data/spec/integration/rails/engines_spec.rb +8 -3
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
- data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
- data/spec/integration/rspec/include_matcher_spec.rb +23 -23
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
- data/spec/integration/rspec/match_matcher_spec.rb +93 -93
- data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/integration/helpers.rb +15 -10
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +6 -6
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
- data/spec/support/shared_examples/active_record.rb +33 -33
- data/spec/support/shared_examples/active_support.rb +125 -4
- data/spec/support/shared_examples/elided_diffs.rb +48 -48
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
- data/spec/support/shared_examples/key.rb +10 -10
- data/spec/unit/active_support/object_inspection_spec.rb +170 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +2 -2
- data/spec/unit/super_diff_spec.rb +64 -0
- metadata +17 -4
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08f4b984e0530c5c4ca5e1ba34b98b380a76712009a1b552a5e21106975293aa'
|
4
|
+
data.tar.gz: 12b49818665c952553c0b052e3fe8166de0c45a5eac7f9862c317560e0a06763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6df90629d86a0c50680b10803cd1839ba0c94828627775fa840e1726fc70b57c6b13be7614ff35c00af960f3ea05530af6ba2d7dc7a3b9f9670fa8d17f75c72
|
7
|
+
data.tar.gz: 56015f9b40eb6f8b03be2c7b02dc641ea7493db0d7d4a8dae929753f7bf94d9a925f0678b8f68c1c2bf7eb705e2c019b3b38f7bfafb805379d8b37b9016f453d
|
data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb
CHANGED
@@ -8,27 +8,39 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
as_lines_when_rendering_to_lines(
|
13
|
-
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
t1.as_lines_when_rendering_to_lines(
|
13
|
+
collection_bookend: :open
|
14
|
+
) do |t2|
|
15
|
+
t2.add_text "#<#{object.class} "
|
14
16
|
|
15
|
-
|
17
|
+
# stree-ignore
|
18
|
+
t2.when_rendering_to_lines do |t3|
|
19
|
+
t3.add_text "{"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
|
-
nested do |
|
19
|
-
insert_separated_list(
|
23
|
+
t1.nested do |t2|
|
24
|
+
t2.insert_separated_list(
|
20
25
|
["id"] + (object.attributes.keys.sort - ["id"])
|
21
|
-
) do |name|
|
22
|
-
as_prefix_when_rendering_to_lines
|
26
|
+
) do |t3, name|
|
27
|
+
t3.as_prefix_when_rendering_to_lines do |t4|
|
28
|
+
t4.add_text "#{name}: "
|
29
|
+
end
|
23
30
|
|
24
|
-
add_inspection_of object.read_attribute(name)
|
31
|
+
t3.add_inspection_of object.read_attribute(name)
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
28
|
-
as_lines_when_rendering_to_lines(
|
29
|
-
|
35
|
+
t1.as_lines_when_rendering_to_lines(
|
36
|
+
collection_bookend: :close
|
37
|
+
) do |t2|
|
38
|
+
# stree-ignore
|
39
|
+
t2.when_rendering_to_lines do |t3|
|
40
|
+
t3.add_text "}"
|
41
|
+
end
|
30
42
|
|
31
|
-
add_text ">"
|
43
|
+
t2.add_text ">"
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
@@ -8,15 +8,24 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
# stree-ignore
|
13
|
+
t1.as_lines_when_rendering_to_lines(
|
14
|
+
collection_bookend: :open
|
15
|
+
) do |t2|
|
16
|
+
t2.add_text "#<ActiveRecord::Relation ["
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
# stree-ignore
|
20
|
+
t1.nested do |t2|
|
21
|
+
t2.insert_array_inspection_of(object)
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
24
|
+
# stree-ignore
|
25
|
+
t1.as_lines_when_rendering_to_lines(
|
26
|
+
collection_bookend: :close
|
27
|
+
) do |t2|
|
28
|
+
t2.add_text "]>"
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
@@ -8,19 +8,34 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
# stree-ignore
|
13
|
+
t1.as_lines_when_rendering_to_lines(
|
14
|
+
collection_bookend: :open
|
15
|
+
) do |t2|
|
16
|
+
t2.add_text "#<HashWithIndifferentAccess {"
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
# stree-ignore
|
20
|
+
t1.when_rendering_to_string do |t2|
|
21
|
+
t2.add_text " "
|
22
|
+
end
|
17
23
|
|
18
|
-
|
24
|
+
# stree-ignore
|
25
|
+
t1.nested do |t2|
|
26
|
+
t2.insert_hash_inspection_of(object)
|
27
|
+
end
|
19
28
|
|
20
|
-
|
29
|
+
# stree-ignore
|
30
|
+
t1.when_rendering_to_string do |t2|
|
31
|
+
t2.add_text " "
|
32
|
+
end
|
21
33
|
|
22
|
-
|
23
|
-
|
34
|
+
# stree-ignore
|
35
|
+
t1.as_lines_when_rendering_to_lines(
|
36
|
+
collection_bookend: :close
|
37
|
+
) do |t2|
|
38
|
+
t2.add_text "}>"
|
24
39
|
end
|
25
40
|
end
|
26
41
|
end
|
data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ActiveSupport
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class OrderedOptions < SuperDiff::ObjectInspection::InspectionTreeBuilders::Hash
|
6
|
+
def self.applies_to?(value)
|
7
|
+
value.is_a?(::ActiveSupport::OrderedOptions)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
# stree-ignore
|
13
|
+
t1.as_lines_when_rendering_to_lines(
|
14
|
+
collection_bookend: :open
|
15
|
+
) do |t2|
|
16
|
+
t2.add_text "#<OrderedOptions {"
|
17
|
+
end
|
18
|
+
|
19
|
+
# stree-ignore
|
20
|
+
t1.when_rendering_to_string do |t2|
|
21
|
+
t2.add_text " "
|
22
|
+
end
|
23
|
+
|
24
|
+
# stree-ignore
|
25
|
+
t1.nested do |t2|
|
26
|
+
t2.insert_hash_inspection_of(object.to_hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
# stree-ignore
|
30
|
+
t1.when_rendering_to_string do |t2|
|
31
|
+
t2.add_text " "
|
32
|
+
end
|
33
|
+
|
34
|
+
# stree-ignore
|
35
|
+
t1.as_lines_when_rendering_to_lines(
|
36
|
+
collection_bookend: :close
|
37
|
+
) do |t2|
|
38
|
+
t2.add_text "}>"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -6,6 +6,10 @@ module SuperDiff
|
|
6
6
|
:HashWithIndifferentAccess,
|
7
7
|
"super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access"
|
8
8
|
)
|
9
|
+
autoload(
|
10
|
+
:OrderedOptions,
|
11
|
+
"super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options"
|
12
|
+
)
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -18,7 +18,8 @@ module SuperDiff
|
|
18
18
|
OperationTreeBuilders::HashWithIndifferentAccess
|
19
19
|
)
|
20
20
|
config.add_extra_inspection_tree_builder_classes(
|
21
|
-
ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess
|
21
|
+
ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess,
|
22
|
+
ObjectInspection::InspectionTreeBuilders::OrderedOptions
|
22
23
|
)
|
23
24
|
end
|
24
25
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module Differs
|
3
|
+
class DateLike < Base
|
4
|
+
def self.applies_to?(expected, actual)
|
5
|
+
SuperDiff.date_like?(expected) && SuperDiff.date_like?(actual)
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def operation_tree_builder_class
|
11
|
+
OperationTreeBuilders::DateLike
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/super_diff/differs.rb
CHANGED
data/lib/super_diff/errors.rb
CHANGED
@@ -7,7 +7,7 @@ module SuperDiff
|
|
7
7
|
@disallowed_node_names = disallowed_node_names
|
8
8
|
@nodes = []
|
9
9
|
|
10
|
-
|
10
|
+
evaluate_block(&block) if block
|
11
11
|
end
|
12
12
|
|
13
13
|
Nodes.registry.each do |node_class|
|
@@ -26,8 +26,7 @@ module SuperDiff
|
|
26
26
|
|
27
27
|
def render_to_string(object)
|
28
28
|
nodes.reduce("") do |string, node|
|
29
|
-
|
30
|
-
string + result
|
29
|
+
string + node.render_to_string(object)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
@@ -52,43 +51,45 @@ module SuperDiff
|
|
52
51
|
.first
|
53
52
|
end
|
54
53
|
|
55
|
-
def evaluate_block(
|
56
|
-
|
54
|
+
def evaluate_block(*args, &block)
|
55
|
+
block.call(self, *args)
|
57
56
|
end
|
58
57
|
|
59
58
|
def insert_array_inspection_of(array)
|
60
|
-
insert_separated_list(array) do |value|
|
59
|
+
insert_separated_list(array) do |t, value|
|
61
60
|
# Have to do these shenanigans so that if value is a hash, Ruby
|
62
61
|
# doesn't try to interpret it as keyword args
|
63
62
|
if SuperDiff::Helpers.ruby_version_matches?(">= 2.7.1")
|
64
|
-
add_inspection_of(value, **{})
|
63
|
+
t.add_inspection_of(value, **{})
|
65
64
|
else
|
66
|
-
add_inspection_of(*[value, {}])
|
65
|
+
t.add_inspection_of(*[value, {}])
|
67
66
|
end
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
70
|
def insert_hash_inspection_of(hash)
|
72
71
|
keys = hash.keys
|
73
|
-
|
74
72
|
format_keys_as_kwargs = keys.all? { |key| key.is_a?(Symbol) }
|
75
73
|
|
76
|
-
insert_separated_list(keys) do |key|
|
74
|
+
insert_separated_list(keys) do |t1, key|
|
77
75
|
if format_keys_as_kwargs
|
78
|
-
|
76
|
+
# stree-ignore
|
77
|
+
t1.as_prefix_when_rendering_to_lines do |t2|
|
78
|
+
t2.add_text "#{key}: "
|
79
|
+
end
|
79
80
|
else
|
80
|
-
as_prefix_when_rendering_to_lines do
|
81
|
-
add_inspection_of key, as_lines: false
|
82
|
-
add_text " => "
|
81
|
+
t1.as_prefix_when_rendering_to_lines do |t2|
|
82
|
+
t2.add_inspection_of key, as_lines: false
|
83
|
+
t2.add_text " => "
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
87
|
# Have to do these shenanigans so that if hash[key] is a hash, Ruby
|
87
88
|
# doesn't try to interpret it as keyword args
|
88
89
|
if SuperDiff::Helpers.ruby_version_matches?(">= 2.7.1")
|
89
|
-
add_inspection_of(hash[key], **{})
|
90
|
+
t1.add_inspection_of(hash[key], **{})
|
90
91
|
else
|
91
|
-
add_inspection_of(*[hash[key], {}])
|
92
|
+
t1.add_inspection_of(*[hash[key], {}])
|
92
93
|
end
|
93
94
|
end
|
94
95
|
end
|
@@ -97,10 +98,14 @@ module SuperDiff
|
|
97
98
|
enumerable.each_with_index do |value, index|
|
98
99
|
as_lines_when_rendering_to_lines(
|
99
100
|
add_comma: index < enumerable.size - 1
|
100
|
-
) do
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
) do |t1|
|
102
|
+
if index > 0
|
103
|
+
# stree-ignore
|
104
|
+
t1.when_rendering_to_string do |t2|
|
105
|
+
t2.add_text " "
|
106
|
+
end
|
107
|
+
end
|
108
|
+
t1.evaluate_block(value, &block)
|
104
109
|
end
|
105
110
|
end
|
106
111
|
end
|
@@ -7,27 +7,46 @@ module SuperDiff
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
InspectionTree.new do |t1|
|
11
|
+
t1.only_when empty do |t2|
|
12
|
+
# stree-ignore
|
13
|
+
t2.as_lines_when_rendering_to_lines do |t3|
|
14
|
+
t3.add_text "[]"
|
15
|
+
end
|
16
16
|
end
|
17
17
|
|
18
|
-
only_when nonempty do
|
19
|
-
|
20
|
-
|
18
|
+
t1.only_when nonempty do |t2|
|
19
|
+
# stree-ignore
|
20
|
+
t2.as_lines_when_rendering_to_lines(
|
21
|
+
collection_bookend: :open
|
22
|
+
) do |t3|
|
23
|
+
t3.add_text "["
|
21
24
|
end
|
22
25
|
|
23
|
-
|
26
|
+
# stree-ignore
|
27
|
+
t2.nested do |t3|
|
28
|
+
t3.insert_array_inspection_of(object)
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
31
|
+
# stree-ignore
|
32
|
+
t2.as_lines_when_rendering_to_lines(
|
33
|
+
collection_bookend: :close
|
34
|
+
) do |t3|
|
35
|
+
t3.add_text "]"
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def empty
|
44
|
+
-> { object.empty? }
|
45
|
+
end
|
46
|
+
|
47
|
+
def nonempty
|
48
|
+
-> { !object.empty? }
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|
33
52
|
end
|
@@ -7,21 +7,31 @@ module SuperDiff
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
InspectionTree.new do
|
11
|
-
as_lines_when_rendering_to_lines(
|
12
|
-
|
10
|
+
InspectionTree.new do |t1|
|
11
|
+
t1.as_lines_when_rendering_to_lines(
|
12
|
+
collection_bookend: :open
|
13
|
+
) do |t2|
|
14
|
+
t2.add_text "#<#{object.class} "
|
13
15
|
|
14
|
-
|
16
|
+
# stree-ignore
|
17
|
+
t2.when_rendering_to_lines do |t3|
|
18
|
+
t3.add_text "{"
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
|
-
nested do |
|
18
|
-
insert_hash_inspection_of(object.attributes_for_super_diff)
|
22
|
+
t1.nested do |t2|
|
23
|
+
t2.insert_hash_inspection_of(object.attributes_for_super_diff)
|
19
24
|
end
|
20
25
|
|
21
|
-
as_lines_when_rendering_to_lines(
|
22
|
-
|
26
|
+
t1.as_lines_when_rendering_to_lines(
|
27
|
+
collection_bookend: :close
|
28
|
+
) do |t2|
|
29
|
+
# stree-ignore
|
30
|
+
t2.when_rendering_to_lines do |t3|
|
31
|
+
t3.add_text "}"
|
32
|
+
end
|
23
33
|
|
24
|
-
add_text ">"
|
34
|
+
t2.add_text ">"
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module ObjectInspection
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class DateLike < Base
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff.date_like?(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
InspectionTree.new do |t1|
|
11
|
+
t1.as_lines_when_rendering_to_lines(
|
12
|
+
collection_bookend: :open
|
13
|
+
) do |t2|
|
14
|
+
t2.add_text "#<#{object.class} "
|
15
|
+
|
16
|
+
# stree-ignore
|
17
|
+
t2.when_rendering_to_lines do |t3|
|
18
|
+
t3.add_text "{"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
t1.when_rendering_to_string do |t2|
|
23
|
+
t2.add_text object.strftime("%Y-%m-%d")
|
24
|
+
end
|
25
|
+
|
26
|
+
t1.when_rendering_to_lines do |t2|
|
27
|
+
t2.nested do |t3|
|
28
|
+
t3.insert_separated_list(%i[year month day]) do |t4, name|
|
29
|
+
t4.add_text name.to_s
|
30
|
+
t4.add_text ": "
|
31
|
+
t4.add_inspection_of object.public_send(name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
t1.as_lines_when_rendering_to_lines(
|
37
|
+
collection_bookend: :close
|
38
|
+
) do |t2|
|
39
|
+
# stree-ignore
|
40
|
+
t2.when_rendering_to_lines do |t3|
|
41
|
+
t3.add_text "}"
|
42
|
+
end
|
43
|
+
|
44
|
+
t2.add_text ">"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -7,47 +7,72 @@ module SuperDiff
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
only_when empty do
|
15
|
-
as_lines_when_rendering_to_lines do
|
16
|
-
add_text do |object|
|
10
|
+
InspectionTree.new do |t1|
|
11
|
+
t1.only_when empty do |t2|
|
12
|
+
t2.as_lines_when_rendering_to_lines do |t3|
|
13
|
+
t3.add_text(
|
17
14
|
"#<#{object.class.name}:" +
|
18
15
|
SuperDiff::Helpers.object_address_for(object) + ">"
|
19
|
-
|
16
|
+
)
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
23
|
-
only_when nonempty do
|
24
|
-
as_lines_when_rendering_to_lines(
|
25
|
-
|
20
|
+
t1.only_when nonempty do |t2|
|
21
|
+
t2.as_lines_when_rendering_to_lines(
|
22
|
+
collection_bookend: :open
|
23
|
+
) do |t3|
|
24
|
+
t3.add_text(
|
26
25
|
"#<#{object.class.name}:" +
|
27
26
|
SuperDiff::Helpers.object_address_for(object)
|
28
|
-
|
27
|
+
)
|
29
28
|
|
30
|
-
|
29
|
+
# stree-ignore
|
30
|
+
t3.when_rendering_to_lines do |t4|
|
31
|
+
t4.add_text " {"
|
32
|
+
end
|
31
33
|
end
|
32
34
|
|
33
|
-
|
35
|
+
# stree-ignore
|
36
|
+
t2.when_rendering_to_string do |t3|
|
37
|
+
t3.add_text " "
|
38
|
+
end
|
34
39
|
|
35
|
-
nested do |
|
36
|
-
insert_separated_list(
|
37
|
-
|
40
|
+
t2.nested do |t3|
|
41
|
+
t3.insert_separated_list(
|
42
|
+
object.instance_variables.sort
|
43
|
+
) do |t4, name|
|
44
|
+
# stree-ignore
|
45
|
+
t4.as_prefix_when_rendering_to_lines do |t5|
|
46
|
+
t5.add_text "#{name}="
|
47
|
+
end
|
38
48
|
|
39
|
-
add_inspection_of object.instance_variable_get(name)
|
49
|
+
t4.add_inspection_of object.instance_variable_get(name)
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
|
-
as_lines_when_rendering_to_lines(
|
44
|
-
|
53
|
+
t2.as_lines_when_rendering_to_lines(
|
54
|
+
collection_bookend: :close
|
55
|
+
) do |t3|
|
56
|
+
# stree-ignore
|
57
|
+
t3.when_rendering_to_lines do |t4|
|
58
|
+
t4.add_text "}"
|
59
|
+
end
|
45
60
|
|
46
|
-
add_text ">"
|
61
|
+
t3.add_text ">"
|
47
62
|
end
|
48
63
|
end
|
49
64
|
end
|
50
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def empty
|
70
|
+
-> { object.instance_variables.empty? }
|
71
|
+
end
|
72
|
+
|
73
|
+
def nonempty
|
74
|
+
-> { !object.instance_variables.empty? }
|
75
|
+
end
|
51
76
|
end
|
52
77
|
end
|
53
78
|
end
|