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
@@ -269,13 +269,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
|
|
269
269
|
diff: proc {
|
270
270
|
plain_line %| #<HashWithIndifferentAccess {|
|
271
271
|
plain_line %| "shipments" => [|
|
272
|
-
plain_line %| {|
|
273
|
-
plain_line %| "estimated_delivery" => {|
|
272
|
+
plain_line %| #<HashWithIndifferentAccess {|
|
273
|
+
plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
|
274
274
|
plain_line %| "from" => "2019-05-06",|
|
275
275
|
expected_line %|- "to" => "2019-05-06"|
|
276
276
|
actual_line %|+ "to" => "2019-05-09"|
|
277
|
-
plain_line %| }
|
278
|
-
plain_line %| }
|
277
|
+
plain_line %| }>|
|
278
|
+
plain_line %| }>|
|
279
279
|
plain_line %| ]|
|
280
280
|
plain_line %| }>|
|
281
281
|
},
|
@@ -333,13 +333,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
|
|
333
333
|
diff: proc {
|
334
334
|
plain_line %| #<HashWithIndifferentAccess {|
|
335
335
|
plain_line %| "shipments" => [|
|
336
|
-
plain_line %| {|
|
337
|
-
plain_line %| "estimated_delivery" => {|
|
336
|
+
plain_line %| #<HashWithIndifferentAccess {|
|
337
|
+
plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
|
338
338
|
plain_line %| "from" => "2019-05-06",|
|
339
339
|
expected_line %|- "to" => "2019-05-06"|
|
340
340
|
actual_line %|+ "to" => "2019-05-09"|
|
341
|
-
plain_line %| }
|
342
|
-
plain_line %| }
|
341
|
+
plain_line %| }>|
|
342
|
+
plain_line %| }>|
|
343
343
|
plain_line %| ]|
|
344
344
|
plain_line %| }>|
|
345
345
|
},
|
@@ -625,13 +625,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
|
|
625
625
|
diff: proc {
|
626
626
|
plain_line %| #<HashWithIndifferentAccess {|
|
627
627
|
plain_line %| "shipments" => [|
|
628
|
-
plain_line %| {|
|
629
|
-
plain_line %| "estimated_delivery" => {|
|
628
|
+
plain_line %| #<HashWithIndifferentAccess {|
|
629
|
+
plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
|
630
630
|
plain_line %| "from" => "2019-05-06",|
|
631
631
|
expected_line %|- "to" => "2019-05-06"|
|
632
632
|
actual_line %|+ "to" => "2019-05-09"|
|
633
|
-
plain_line %| }
|
634
|
-
plain_line %| }
|
633
|
+
plain_line %| }>|
|
634
|
+
plain_line %| }>|
|
635
635
|
plain_line %| ]|
|
636
636
|
plain_line %| }>|
|
637
637
|
},
|
@@ -689,13 +689,13 @@ shared_examples_for "integration with HashWithIndifferentAccess" do
|
|
689
689
|
diff: proc {
|
690
690
|
plain_line %| #<HashWithIndifferentAccess {|
|
691
691
|
plain_line %| "shipments" => [|
|
692
|
-
plain_line %| {|
|
693
|
-
plain_line %| "estimated_delivery" => {|
|
692
|
+
plain_line %| #<HashWithIndifferentAccess {|
|
693
|
+
plain_line %| "estimated_delivery" => #<HashWithIndifferentAccess {|
|
694
694
|
plain_line %| "from" => "2019-05-06",|
|
695
695
|
expected_line %|- "to" => "2019-05-06"|
|
696
696
|
actual_line %|+ "to" => "2019-05-09"|
|
697
|
-
plain_line %| }
|
698
|
-
plain_line %| }
|
697
|
+
plain_line %| }>|
|
698
|
+
plain_line %| }>|
|
699
699
|
plain_line %| ]|
|
700
700
|
plain_line %| }>|
|
701
701
|
},
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module UnitTests
|
3
|
+
def with_configuration(configuration)
|
4
|
+
old_configuration = SuperDiff.configuration.dup
|
5
|
+
SuperDiff.configuration.merge!(configuration)
|
6
|
+
yield.tap do
|
7
|
+
SuperDiff.configuration.merge!(old_configuration)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def colored(*args, **opts, &block)
|
12
|
+
SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module UnitTests
|
3
|
+
def match_output(expected_output)
|
4
|
+
MatchOutputMatcher.new(expected_output)
|
5
|
+
end
|
6
|
+
|
7
|
+
class MatchOutputMatcher
|
8
|
+
extend AttrExtras.mixin
|
9
|
+
|
10
|
+
pattr_initialize :expected_output
|
11
|
+
attr_private :actual_output
|
12
|
+
|
13
|
+
def matches?(actual_output)
|
14
|
+
@actual_output = actual_output
|
15
|
+
actual_output == expected_output
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure_message
|
19
|
+
message =
|
20
|
+
"Expected colored output to be printed, but got a mismatch.\n\n" +
|
21
|
+
"Expected output:\n\n" +
|
22
|
+
SuperDiff::Test::OutputHelpers.bookended(expected_output) +
|
23
|
+
"\n" +
|
24
|
+
"Actual output:\n\n" +
|
25
|
+
SuperDiff::Test::OutputHelpers.bookended(actual_output)
|
26
|
+
|
27
|
+
if ["1", "true"].include?(ENV["SHOW_DIFF"])
|
28
|
+
::RSpec::Matchers::ExpectedsForMultipleDiffs.
|
29
|
+
from(expected_output).
|
30
|
+
message_with_diff(
|
31
|
+
message,
|
32
|
+
::RSpec::Expectations.differ,
|
33
|
+
actual_output,
|
34
|
+
)
|
35
|
+
else
|
36
|
+
message
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe SuperDiff, type: :unit do
|
4
|
+
describe ".inspect_object", "for ActiveRecord objects", active_record: true do
|
5
|
+
context "given an ActiveRecord object" do
|
6
|
+
context "given as_lines: false" do
|
7
|
+
it "returns an inspected version of the object" do
|
8
|
+
string = described_class.inspect_object(
|
9
|
+
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
10
|
+
name: "Elliot",
|
11
|
+
age: 31,
|
12
|
+
),
|
13
|
+
as_lines: false,
|
14
|
+
)
|
15
|
+
expect(string).to eq(
|
16
|
+
%(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "given as_lines: true" do
|
22
|
+
it "returns an inspected version of the object as multiple Lines" do
|
23
|
+
tiered_lines = described_class.inspect_object(
|
24
|
+
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
25
|
+
name: "Elliot",
|
26
|
+
age: 31,
|
27
|
+
),
|
28
|
+
as_lines: true,
|
29
|
+
type: :delete,
|
30
|
+
indentation_level: 1,
|
31
|
+
)
|
32
|
+
expect(tiered_lines).to match([
|
33
|
+
an_object_having_attributes(
|
34
|
+
type: :delete,
|
35
|
+
indentation_level: 1,
|
36
|
+
value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
|
37
|
+
collection_bookend: :open,
|
38
|
+
),
|
39
|
+
an_object_having_attributes(
|
40
|
+
type: :delete,
|
41
|
+
indentation_level: 2,
|
42
|
+
prefix: %(id: ),
|
43
|
+
value: %(nil),
|
44
|
+
add_comma: true,
|
45
|
+
),
|
46
|
+
an_object_having_attributes(
|
47
|
+
type: :delete,
|
48
|
+
indentation_level: 2,
|
49
|
+
prefix: %(age: ),
|
50
|
+
value: %(31),
|
51
|
+
add_comma: true,
|
52
|
+
),
|
53
|
+
an_object_having_attributes(
|
54
|
+
type: :delete,
|
55
|
+
indentation_level: 2,
|
56
|
+
prefix: %(name: ),
|
57
|
+
value: %("Elliot"),
|
58
|
+
add_comma: false,
|
59
|
+
),
|
60
|
+
an_object_having_attributes(
|
61
|
+
type: :delete,
|
62
|
+
indentation_level: 1,
|
63
|
+
value: %(}>),
|
64
|
+
collection_bookend: :close,
|
65
|
+
),
|
66
|
+
])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "given an ActiveRecord::Relation object" do
|
72
|
+
context "given as_lines: false" do
|
73
|
+
it "returns an inspected version of the Relation" do
|
74
|
+
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
75
|
+
name: "Marty",
|
76
|
+
age: 19,
|
77
|
+
)
|
78
|
+
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
79
|
+
name: "Jennifer",
|
80
|
+
age: 17,
|
81
|
+
)
|
82
|
+
|
83
|
+
string = described_class.inspect_object(
|
84
|
+
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
85
|
+
as_lines: false,
|
86
|
+
)
|
87
|
+
|
88
|
+
expect(string).to eq(
|
89
|
+
%(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>)
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "given as_lines: true" do
|
95
|
+
it "returns an inspected version of the Relation as multiple Lines" do
|
96
|
+
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
97
|
+
name: "Marty",
|
98
|
+
age: 19,
|
99
|
+
)
|
100
|
+
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
101
|
+
name: "Jennifer",
|
102
|
+
age: 17,
|
103
|
+
)
|
104
|
+
|
105
|
+
tiered_lines = described_class.inspect_object(
|
106
|
+
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
107
|
+
as_lines: true,
|
108
|
+
type: :delete,
|
109
|
+
indentation_level: 1,
|
110
|
+
)
|
111
|
+
|
112
|
+
expect(tiered_lines).to match([
|
113
|
+
an_object_having_attributes(
|
114
|
+
type: :delete,
|
115
|
+
indentation_level: 1,
|
116
|
+
value: %(#<ActiveRecord::Relation [),
|
117
|
+
collection_bookend: :open,
|
118
|
+
),
|
119
|
+
an_object_having_attributes(
|
120
|
+
type: :delete,
|
121
|
+
indentation_level: 2,
|
122
|
+
value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
|
123
|
+
collection_bookend: :open,
|
124
|
+
),
|
125
|
+
an_object_having_attributes(
|
126
|
+
type: :delete,
|
127
|
+
indentation_level: 3,
|
128
|
+
prefix: %(id: ),
|
129
|
+
value: %(1),
|
130
|
+
add_comma: true,
|
131
|
+
),
|
132
|
+
an_object_having_attributes(
|
133
|
+
type: :delete,
|
134
|
+
indentation_level: 3,
|
135
|
+
prefix: %(age: ),
|
136
|
+
value: %(19),
|
137
|
+
add_comma: true,
|
138
|
+
),
|
139
|
+
an_object_having_attributes(
|
140
|
+
type: :delete,
|
141
|
+
indentation_level: 3,
|
142
|
+
prefix: %(name: ),
|
143
|
+
value: %("Marty"),
|
144
|
+
add_comma: false,
|
145
|
+
),
|
146
|
+
an_object_having_attributes(
|
147
|
+
type: :delete,
|
148
|
+
indentation_level: 2,
|
149
|
+
value: %(}>),
|
150
|
+
collection_bookend: :close,
|
151
|
+
),
|
152
|
+
an_object_having_attributes(
|
153
|
+
type: :delete,
|
154
|
+
indentation_level: 2,
|
155
|
+
value: %(#<SuperDiff::Test::Models::ActiveRecord::Person {),
|
156
|
+
collection_bookend: :open,
|
157
|
+
),
|
158
|
+
an_object_having_attributes(
|
159
|
+
type: :delete,
|
160
|
+
indentation_level: 3,
|
161
|
+
prefix: %(id: ),
|
162
|
+
value: %(2),
|
163
|
+
add_comma: true,
|
164
|
+
),
|
165
|
+
an_object_having_attributes(
|
166
|
+
type: :delete,
|
167
|
+
indentation_level: 3,
|
168
|
+
prefix: %(age: ),
|
169
|
+
value: %(17),
|
170
|
+
add_comma: true,
|
171
|
+
),
|
172
|
+
an_object_having_attributes(
|
173
|
+
type: :delete,
|
174
|
+
indentation_level: 3,
|
175
|
+
prefix: %(name: ),
|
176
|
+
value: %("Jennifer"),
|
177
|
+
add_comma: false,
|
178
|
+
),
|
179
|
+
an_object_having_attributes(
|
180
|
+
type: :delete,
|
181
|
+
indentation_level: 2,
|
182
|
+
value: %(}>),
|
183
|
+
collection_bookend: :close,
|
184
|
+
),
|
185
|
+
an_object_having_attributes(
|
186
|
+
type: :delete,
|
187
|
+
indentation_level: 1,
|
188
|
+
value: %(]>),
|
189
|
+
collection_bookend: :close,
|
190
|
+
),
|
191
|
+
])
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "given a HashWithIndifferentAccess" do
|
197
|
+
context "given as_lines: false" do
|
198
|
+
it "returns an inspected version of the object" do
|
199
|
+
string = described_class.inspect_object(
|
200
|
+
HashWithIndifferentAccess.new({
|
201
|
+
line_1: "123 Main St.",
|
202
|
+
city: "Hill Valley",
|
203
|
+
state: "CA",
|
204
|
+
zip: "90382",
|
205
|
+
}),
|
206
|
+
as_lines: false,
|
207
|
+
)
|
208
|
+
expect(string).to eq(
|
209
|
+
%(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>),
|
210
|
+
)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "given as_lines: true" do
|
215
|
+
it "returns an inspected version of the object as multiple Lines" do
|
216
|
+
tiered_lines = described_class.inspect_object(
|
217
|
+
HashWithIndifferentAccess.new({
|
218
|
+
line_1: "123 Main St.",
|
219
|
+
city: "Hill Valley",
|
220
|
+
state: "CA",
|
221
|
+
zip: "90382",
|
222
|
+
}),
|
223
|
+
as_lines: true,
|
224
|
+
type: :delete,
|
225
|
+
indentation_level: 1,
|
226
|
+
)
|
227
|
+
expect(tiered_lines).to match([
|
228
|
+
an_object_having_attributes(
|
229
|
+
type: :delete,
|
230
|
+
indentation_level: 1,
|
231
|
+
value: %(#<HashWithIndifferentAccess {),
|
232
|
+
collection_bookend: :open,
|
233
|
+
),
|
234
|
+
an_object_having_attributes(
|
235
|
+
type: :delete,
|
236
|
+
indentation_level: 2,
|
237
|
+
prefix: %("line_1" => ),
|
238
|
+
value: %("123 Main St."),
|
239
|
+
add_comma: true,
|
240
|
+
),
|
241
|
+
an_object_having_attributes(
|
242
|
+
type: :delete,
|
243
|
+
indentation_level: 2,
|
244
|
+
prefix: %("city" => ),
|
245
|
+
value: %("Hill Valley"),
|
246
|
+
add_comma: true,
|
247
|
+
),
|
248
|
+
an_object_having_attributes(
|
249
|
+
type: :delete,
|
250
|
+
indentation_level: 2,
|
251
|
+
prefix: %("state" => ),
|
252
|
+
value: %("CA"),
|
253
|
+
add_comma: true,
|
254
|
+
),
|
255
|
+
an_object_having_attributes(
|
256
|
+
type: :delete,
|
257
|
+
indentation_level: 2,
|
258
|
+
prefix: %("zip" => ),
|
259
|
+
value: %("90382"),
|
260
|
+
add_comma: false,
|
261
|
+
),
|
262
|
+
an_object_having_attributes(
|
263
|
+
type: :delete,
|
264
|
+
indentation_level: 1,
|
265
|
+
value: %(}>),
|
266
|
+
collection_bookend: :close,
|
267
|
+
),
|
268
|
+
])
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|