super_diff 0.12.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -19
- data/lib/super_diff/active_record/differs/active_record_relation.rb +2 -0
- data/lib/super_diff/active_record/differs.rb +3 -1
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +7 -5
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +12 -10
- data/lib/super_diff/active_record/inspection_tree_builders.rb +4 -2
- data/lib/super_diff/active_record/monkey_patches.rb +4 -2
- data/lib/super_diff/active_record/object_inspection.rb +6 -4
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +3 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +3 -1
- data/lib/super_diff/active_record/operation_tree_builders.rb +4 -2
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +4 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +3 -1
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +2 -0
- data/lib/super_diff/active_record/operation_trees.rb +3 -1
- data/lib/super_diff/active_record.rb +10 -8
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +2 -0
- data/lib/super_diff/active_support/differs.rb +3 -1
- data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +16 -14
- data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +16 -14
- data/lib/super_diff/active_support/inspection_tree_builders.rb +4 -2
- data/lib/super_diff/active_support/object_inspection.rb +6 -4
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +6 -4
- data/lib/super_diff/active_support/operation_tree_builders.rb +3 -1
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +4 -2
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +3 -1
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +2 -0
- data/lib/super_diff/active_support/operation_trees.rb +3 -1
- data/lib/super_diff/active_support.rb +8 -6
- data/lib/super_diff/basic/diff_formatters/collection.rb +18 -18
- data/lib/super_diff/basic/diff_formatters/multiline_string.rb +2 -0
- data/lib/super_diff/basic/diff_formatters.rb +4 -2
- data/lib/super_diff/basic/differs/array.rb +2 -0
- data/lib/super_diff/basic/differs/custom_object.rb +3 -1
- data/lib/super_diff/basic/differs/date_like.rb +2 -0
- data/lib/super_diff/basic/differs/default_object.rb +3 -1
- data/lib/super_diff/basic/differs/hash.rb +2 -0
- data/lib/super_diff/basic/differs/multiline_string.rb +2 -0
- data/lib/super_diff/basic/differs/time_like.rb +2 -0
- data/lib/super_diff/basic/differs.rb +11 -9
- data/lib/super_diff/basic/inspection_tree_builders/array.rb +5 -3
- data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +5 -3
- data/lib/super_diff/basic/inspection_tree_builders/data_object.rb +42 -0
- data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +7 -5
- data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +7 -5
- data/lib/super_diff/basic/inspection_tree_builders/hash.rb +7 -5
- data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +3 -1
- data/lib/super_diff/basic/inspection_tree_builders/range_object.rb +19 -0
- data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +8 -8
- data/lib/super_diff/basic/inspection_tree_builders.rb +18 -8
- data/lib/super_diff/basic/operation_tree_builders/array.rb +6 -4
- data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +3 -1
- data/lib/super_diff/basic/operation_tree_builders/data_object.rb +20 -0
- data/lib/super_diff/basic/operation_tree_builders/date_like.rb +2 -0
- data/lib/super_diff/basic/operation_tree_builders/default_object.rb +32 -31
- data/lib/super_diff/basic/operation_tree_builders/hash.rb +49 -46
- data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +5 -3
- data/lib/super_diff/basic/operation_tree_builders/time_like.rb +5 -3
- data/lib/super_diff/basic/operation_tree_builders.rb +15 -9
- data/lib/super_diff/basic/operation_tree_flatteners/array.rb +4 -2
- data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +11 -11
- data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +5 -3
- data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +6 -5
- data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +5 -3
- data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +3 -1
- data/lib/super_diff/basic/operation_tree_flatteners.rb +8 -6
- data/lib/super_diff/basic/operation_trees/array.rb +2 -0
- data/lib/super_diff/basic/operation_trees/custom_object.rb +2 -0
- data/lib/super_diff/basic/operation_trees/default_object.rb +6 -4
- data/lib/super_diff/basic/operation_trees/hash.rb +2 -0
- data/lib/super_diff/basic/operation_trees/multiline_string.rb +3 -1
- data/lib/super_diff/basic/operation_trees.rb +9 -7
- data/lib/super_diff/basic.rb +12 -7
- data/lib/super_diff/core/abstract_differ.rb +2 -0
- data/lib/super_diff/core/abstract_inspection_tree_builder.rb +2 -0
- data/lib/super_diff/core/abstract_operation_tree.rb +4 -2
- data/lib/super_diff/core/abstract_operation_tree_builder.rb +15 -18
- data/lib/super_diff/core/abstract_operation_tree_flattener.rb +5 -3
- data/lib/super_diff/core/binary_operation.rb +3 -1
- data/lib/super_diff/core/colorized_document_extensions.rb +2 -0
- data/lib/super_diff/core/configuration.rb +23 -43
- data/lib/super_diff/core/differ_dispatcher.rb +4 -2
- data/lib/super_diff/core/gem_version.rb +2 -0
- data/lib/super_diff/core/helpers.rb +14 -12
- data/lib/super_diff/core/implementation_checks.rb +6 -2
- data/lib/super_diff/core/inspection_tree.rb +38 -38
- data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +5 -5
- data/lib/super_diff/core/inspection_tree_nodes/as_lines_when_rendering_to_lines.rb +3 -1
- data/lib/super_diff/core/inspection_tree_nodes/as_prefix_when_rendering_to_lines.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/as_prelude_when_rendering_to_lines.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/as_single_line.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/base.rb +9 -9
- data/lib/super_diff/core/inspection_tree_nodes/inspection.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/nesting.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/only_when.rb +5 -1
- data/lib/super_diff/core/inspection_tree_nodes/text.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes/when_empty.rb +3 -1
- data/lib/super_diff/core/inspection_tree_nodes/when_non_empty.rb +3 -1
- data/lib/super_diff/core/inspection_tree_nodes/when_rendering_to_lines.rb +3 -1
- data/lib/super_diff/core/inspection_tree_nodes/when_rendering_to_string.rb +2 -0
- data/lib/super_diff/core/inspection_tree_nodes.rb +16 -14
- data/lib/super_diff/core/line.rb +9 -7
- data/lib/super_diff/core/no_differ_available_error.rb +7 -5
- data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +5 -3
- data/lib/super_diff/core/no_operation_tree_available_error.rb +4 -2
- data/lib/super_diff/core/no_operation_tree_builder_available_error.rb +7 -5
- data/lib/super_diff/core/operation_tree_builder_dispatcher.rb +3 -3
- data/lib/super_diff/core/operation_tree_finder.rb +8 -8
- data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +2 -0
- data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +2 -0
- data/lib/super_diff/core/recursion_guard.rb +6 -4
- data/lib/super_diff/core/tiered_lines.rb +2 -0
- data/lib/super_diff/core/tiered_lines_elider.rb +53 -54
- data/lib/super_diff/core/tiered_lines_formatter.rb +6 -4
- data/lib/super_diff/core/unary_operation.rb +2 -0
- data/lib/super_diff/core.rb +31 -29
- data/lib/super_diff/csi/bold_sequence.rb +2 -0
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/color_sequence_block.rb +3 -1
- data/lib/super_diff/csi/colorized_document.rb +7 -9
- data/lib/super_diff/csi/document.rb +15 -18
- data/lib/super_diff/csi/eight_bit_color.rb +32 -37
- data/lib/super_diff/csi/four_bit_color.rb +12 -9
- data/lib/super_diff/csi/reset_sequence.rb +2 -0
- data/lib/super_diff/csi/twenty_four_bit_color.rb +22 -21
- data/lib/super_diff/csi/uncolorized_document.rb +2 -0
- data/lib/super_diff/csi.rb +12 -42
- data/lib/super_diff/differs.rb +6 -4
- data/lib/super_diff/equality_matchers/array.rb +18 -16
- data/lib/super_diff/equality_matchers/base.rb +6 -4
- data/lib/super_diff/equality_matchers/default.rb +5 -3
- data/lib/super_diff/equality_matchers/defaults.rb +3 -1
- data/lib/super_diff/equality_matchers/hash.rb +18 -16
- data/lib/super_diff/equality_matchers/main.rb +3 -1
- data/lib/super_diff/equality_matchers/multiline_string.rb +18 -16
- data/lib/super_diff/equality_matchers/primitive.rb +15 -13
- data/lib/super_diff/equality_matchers/singleline_string.rb +16 -14
- data/lib/super_diff/equality_matchers.rb +11 -9
- data/lib/super_diff/errors.rb +4 -2
- data/lib/super_diff/object_inspection.rb +17 -15
- data/lib/super_diff/operation_tree_builders.rb +6 -4
- data/lib/super_diff/operation_tree_flatteners.rb +6 -4
- data/lib/super_diff/operation_trees.rb +6 -4
- data/lib/super_diff/operations.rb +4 -2
- data/lib/super_diff/rails.rb +4 -2
- data/lib/super_diff/rspec/augmented_matcher.rb +3 -1
- data/lib/super_diff/rspec/differ.rb +16 -7
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -0
- data/lib/super_diff/rspec/differs/collection_including.rb +2 -0
- data/lib/super_diff/rspec/differs/hash_including.rb +2 -0
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -0
- data/lib/super_diff/rspec/differs.rb +6 -4
- data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +12 -10
- data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +10 -8
- data/lib/super_diff/rspec/inspection_tree_builders/double.rb +20 -18
- data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +2 -0
- data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +10 -8
- data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +2 -0
- data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +2 -0
- data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +12 -10
- data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +2 -0
- data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +6 -4
- data/lib/super_diff/rspec/inspection_tree_builders.rb +12 -10
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +12 -12
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +19 -17
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +3 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +7 -5
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +6 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +5 -3
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +20 -18
- data/lib/super_diff/rspec/matcher_text_builders.rb +9 -7
- data/lib/super_diff/rspec/matcher_text_template.rb +34 -39
- data/lib/super_diff/rspec/monkey_patches.rb +129 -56
- data/lib/super_diff/rspec/object_inspection.rb +7 -5
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +2 -0
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +2 -0
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +6 -4
- data/lib/super_diff/rspec-rails.rb +4 -2
- data/lib/super_diff/rspec.rb +27 -14
- data/lib/super_diff/version.rb +3 -1
- data/lib/super_diff.rb +24 -27
- data/super_diff.gemspec +20 -18
- metadata +15 -182
- data/spec/examples.txt +0 -704
- data/spec/integration/rails/active_record_spec.rb +0 -21
- data/spec/integration/rails/active_support_spec.rb +0 -19
- data/spec/integration/rails/engines_spec.rb +0 -25
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +0 -21
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +0 -58
- data/spec/integration/rspec/be_matcher_spec.rb +0 -605
- data/spec/integration/rspec/be_nil_matcher_spec.rb +0 -57
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +0 -615
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +0 -62
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +0 -377
- data/spec/integration/rspec/eq_matcher_spec.rb +0 -1066
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +0 -177
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +0 -443
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +0 -478
- data/spec/integration/rspec/include_matcher_spec.rb +0 -452
- data/spec/integration/rspec/magic_metadata_spec.rb +0 -51
- data/spec/integration/rspec/match_array_matcher_spec.rb +0 -424
- data/spec/integration/rspec/match_matcher_spec.rb +0 -1359
- data/spec/integration/rspec/raise_error_matcher_spec.rb +0 -1488
- data/spec/integration/rspec/respond_to_matcher_spec.rb +0 -999
- data/spec/integration/rspec/third_party_matcher_spec.rb +0 -245
- data/spec/integration/rspec/unhandled_errors_spec.rb +0 -150
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +0 -90
- data/spec/support/colorizer.rb +0 -9
- data/spec/support/command_runner.rb +0 -253
- data/spec/support/helpers.rb +0 -21
- data/spec/support/integration/helpers.rb +0 -124
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +0 -104
- data/spec/support/integration/matchers.rb +0 -177
- data/spec/support/integration/test_programs/base.rb +0 -143
- data/spec/support/integration/test_programs/plain.rb +0 -19
- data/spec/support/integration/test_programs/rspec_active_record.rb +0 -20
- data/spec/support/integration/test_programs/rspec_active_support.rb +0 -20
- data/spec/support/integration/test_programs/rspec_rails.rb +0 -20
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +0 -20
- data/spec/support/models/a.rb +0 -11
- data/spec/support/models/active_record/person.rb +0 -28
- data/spec/support/models/active_record/query.rb +0 -15
- data/spec/support/models/active_record/shipping_address.rb +0 -24
- data/spec/support/models/customer.rb +0 -22
- data/spec/support/models/empty_class.rb +0 -6
- data/spec/support/models/item.rb +0 -10
- data/spec/support/models/order.rb +0 -9
- data/spec/support/models/person.rb +0 -20
- data/spec/support/models/player.rb +0 -30
- data/spec/support/models/shipping_address.rb +0 -25
- data/spec/support/shared_examples/active_record.rb +0 -428
- data/spec/support/shared_examples/active_support.rb +0 -188
- data/spec/support/shared_examples/elided_diffs.rb +0 -938
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +0 -749
- data/spec/support/shared_examples/key.rb +0 -123
- data/spec/support/unit/helpers.rb +0 -24
- data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +0 -39
- data/spec/support/unit/matchers/match_output.rb +0 -40
- data/spec/unit/active_record/object_inspection_spec.rb +0 -289
- data/spec/unit/active_support/object_inspection_spec.rb +0 -170
- data/spec/unit/basic/operation_tree_flatteners/array_spec.rb +0 -637
- data/spec/unit/basic/operation_tree_flatteners/custom_object_spec.rb +0 -685
- data/spec/unit/basic/operation_tree_flatteners/default_object_spec.rb +0 -685
- data/spec/unit/basic/operation_tree_flatteners/hash_spec.rb +0 -671
- data/spec/unit/basic/operation_tree_flatteners/multiline_string_spec.rb +0 -131
- data/spec/unit/core/helpers_spec.rb +0 -68
- data/spec/unit/core/tiered_lines_elider_spec.rb +0 -6328
- data/spec/unit/core/tiered_lines_formatter_spec.rb +0 -131
- data/spec/unit/deprecations_spec.rb +0 -176
- data/spec/unit/equality_matchers/main_spec.rb +0 -1842
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +0 -23
- data/spec/unit/rspec/matchers/be_falsey_spec.rb +0 -9
- data/spec/unit/rspec/matchers/be_nil_spec.rb +0 -9
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +0 -31
- data/spec/unit/rspec/matchers/be_spec.rb +0 -17
- data/spec/unit/rspec/matchers/be_truthy_spec.rb +0 -9
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +0 -11
- data/spec/unit/rspec/matchers/eq_spec.rb +0 -9
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +0 -11
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +0 -21
- data/spec/unit/rspec/matchers/include_spec.rb +0 -21
- data/spec/unit/rspec/matchers/match_array_spec.rb +0 -11
- data/spec/unit/rspec/matchers/match_spec.rb +0 -9
- data/spec/unit/rspec/matchers/raise_error_spec.rb +0 -77
- data/spec/unit/rspec/matchers/respond_to_spec.rb +0 -85
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +0 -91
- data/spec/unit/rspec/object_inspection_spec.rb +0 -471
- data/spec/unit/super_diff_spec.rb +0 -2115
@@ -1,1842 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe SuperDiff::EqualityMatchers::Main, type: :unit do
|
4
|
-
describe "#call" do
|
5
|
-
context "given the same integers" do
|
6
|
-
it "returns an empty string" do
|
7
|
-
output = described_class.call(expected: 1, actual: 1)
|
8
|
-
|
9
|
-
expect(output).to eq("")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "given the same numbers (even if they're different types)" do
|
14
|
-
it "returns an empty string" do
|
15
|
-
output = described_class.call(expected: 1, actual: 1.0)
|
16
|
-
|
17
|
-
expect(output).to eq("")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "given differing numbers" do
|
22
|
-
it "returns a message along with a comparison" do
|
23
|
-
actual_output = described_class.call(expected: 42, actual: 1)
|
24
|
-
|
25
|
-
expected_output = <<~STR.strip
|
26
|
-
Differing numbers.
|
27
|
-
|
28
|
-
#{
|
29
|
-
colored do
|
30
|
-
expected_line "Expected: 42"
|
31
|
-
actual_line " Actual: 1"
|
32
|
-
end
|
33
|
-
}
|
34
|
-
STR
|
35
|
-
|
36
|
-
expect(actual_output).to match_output(expected_output)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "given the same symbol" do
|
41
|
-
it "returns an empty string" do
|
42
|
-
output = described_class.call(expected: :foo, actual: :foo)
|
43
|
-
|
44
|
-
expect(output).to eq("")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "given differing symbols" do
|
49
|
-
it "returns a message along with a comparison" do
|
50
|
-
actual_output = described_class.call(expected: :foo, actual: :bar)
|
51
|
-
|
52
|
-
expected_output = <<~STR.strip
|
53
|
-
Differing symbols.
|
54
|
-
|
55
|
-
#{
|
56
|
-
colored do
|
57
|
-
expected_line "Expected: :foo"
|
58
|
-
actual_line " Actual: :bar"
|
59
|
-
end
|
60
|
-
}
|
61
|
-
STR
|
62
|
-
|
63
|
-
expect(actual_output).to match_output(expected_output)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "given the same string" do
|
68
|
-
it "returns an empty string" do
|
69
|
-
output = described_class.call(expected: "", actual: "")
|
70
|
-
|
71
|
-
expect(output).to eq("")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "given completely different single-line strings" do
|
76
|
-
it "returns a message along with the diff" do
|
77
|
-
actual_output =
|
78
|
-
described_class.call(expected: "Marty", actual: "Jennifer")
|
79
|
-
|
80
|
-
expected_output = <<~STR.strip
|
81
|
-
Differing strings.
|
82
|
-
|
83
|
-
#{
|
84
|
-
colored do
|
85
|
-
expected_line %(Expected: "Marty")
|
86
|
-
actual_line %( Actual: "Jennifer")
|
87
|
-
end
|
88
|
-
}
|
89
|
-
STR
|
90
|
-
|
91
|
-
expect(actual_output).to match_output(expected_output)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "given closely different single-line strings" do
|
96
|
-
it "returns a message along with the diff" do
|
97
|
-
actual_output =
|
98
|
-
described_class.call(expected: "Marty", actual: "Marty McFly")
|
99
|
-
|
100
|
-
expected_output = <<~STR.strip
|
101
|
-
Differing strings.
|
102
|
-
|
103
|
-
#{
|
104
|
-
colored do
|
105
|
-
expected_line %(Expected: "Marty")
|
106
|
-
actual_line %( Actual: "Marty McFly")
|
107
|
-
end
|
108
|
-
}
|
109
|
-
STR
|
110
|
-
|
111
|
-
expect(actual_output).to match_output(expected_output)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "given a single-line string and a multi-line string" do
|
116
|
-
it "returns a message along with the diff" do
|
117
|
-
actual_output =
|
118
|
-
described_class.call(
|
119
|
-
expected: "Something entirely different",
|
120
|
-
actual: "This is a line\nAnd that's another line\n"
|
121
|
-
)
|
122
|
-
|
123
|
-
expected_output = <<~STR.strip
|
124
|
-
Differing strings.
|
125
|
-
|
126
|
-
#{
|
127
|
-
colored do
|
128
|
-
expected_line %(Expected: "Something entirely different")
|
129
|
-
actual_line %( Actual: "This is a line\\nAnd that's another line\\n")
|
130
|
-
end
|
131
|
-
}
|
132
|
-
STR
|
133
|
-
|
134
|
-
expect(actual_output).to match_output(expected_output)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "given a multi-line string and a single-line string" do
|
139
|
-
it "returns a message along with the diff" do
|
140
|
-
actual_output =
|
141
|
-
described_class.call(
|
142
|
-
expected: "This is a line\nAnd that's another line\n",
|
143
|
-
actual: "Something entirely different"
|
144
|
-
)
|
145
|
-
|
146
|
-
expected_output = <<~STR.strip
|
147
|
-
Differing strings.
|
148
|
-
|
149
|
-
#{
|
150
|
-
colored do
|
151
|
-
expected_line %(Expected: "This is a line\\nAnd that's another line\\n")
|
152
|
-
actual_line %( Actual: "Something entirely different")
|
153
|
-
end
|
154
|
-
}
|
155
|
-
STR
|
156
|
-
|
157
|
-
expect(actual_output).to match_output(expected_output)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "given closely different multi-line strings" do
|
162
|
-
it "returns a message along with the diff" do
|
163
|
-
actual_output =
|
164
|
-
described_class.call(
|
165
|
-
expected:
|
166
|
-
"This is a line\nAnd that's a line\nAnd there's a line too",
|
167
|
-
actual:
|
168
|
-
"This is a line\nSomething completely different\nAnd there's a line too"
|
169
|
-
)
|
170
|
-
|
171
|
-
expected_output = <<~STR.strip
|
172
|
-
Differing strings.
|
173
|
-
|
174
|
-
#{
|
175
|
-
colored do
|
176
|
-
expected_line %(Expected: "This is a line\\nAnd that's a line\\nAnd there's a line too")
|
177
|
-
actual_line %( Actual: "This is a line\\nSomething completely different\\nAnd there's a line too")
|
178
|
-
end
|
179
|
-
}
|
180
|
-
|
181
|
-
Diff:
|
182
|
-
|
183
|
-
#{
|
184
|
-
colored do
|
185
|
-
plain_line %( This is a line\\n)
|
186
|
-
expected_line %(- And that's a line\\n)
|
187
|
-
actual_line %(+ Something completely different\\n)
|
188
|
-
plain_line " And there's a line too"
|
189
|
-
end
|
190
|
-
}
|
191
|
-
STR
|
192
|
-
|
193
|
-
expect(actual_output).to match_output(expected_output)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context "given completely different multi-line strings" do
|
198
|
-
it "returns a message along with the diff" do
|
199
|
-
actual_output =
|
200
|
-
described_class.call(
|
201
|
-
expected: "This is a line\nAnd that's a line\n",
|
202
|
-
actual: "Something completely different\nAnd something else too\n"
|
203
|
-
)
|
204
|
-
|
205
|
-
expected_output = <<~STR.strip
|
206
|
-
Differing strings.
|
207
|
-
|
208
|
-
#{
|
209
|
-
colored do
|
210
|
-
expected_line %(Expected: "This is a line\\nAnd that's a line\\n")
|
211
|
-
actual_line %( Actual: "Something completely different\\nAnd something else too\\n")
|
212
|
-
end
|
213
|
-
}
|
214
|
-
|
215
|
-
Diff:
|
216
|
-
|
217
|
-
#{
|
218
|
-
colored do
|
219
|
-
expected_line %(- This is a line\\n)
|
220
|
-
expected_line %(- And that's a line\\n)
|
221
|
-
actual_line %(+ Something completely different\\n)
|
222
|
-
actual_line %(+ And something else too\\n)
|
223
|
-
end
|
224
|
-
}
|
225
|
-
STR
|
226
|
-
|
227
|
-
expect(actual_output).to match_output(expected_output)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "given multi-line strings that contain color codes" do
|
232
|
-
it "escapes the color codes" do
|
233
|
-
colors = [
|
234
|
-
SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
|
235
|
-
SuperDiff::Csi::EightBitColor.new(
|
236
|
-
red: 3,
|
237
|
-
green: 8,
|
238
|
-
blue: 4,
|
239
|
-
layer: :foreground
|
240
|
-
),
|
241
|
-
SuperDiff::Csi::TwentyFourBitColor.new(
|
242
|
-
red: 47,
|
243
|
-
green: 164,
|
244
|
-
blue: 59,
|
245
|
-
layer: :foreground
|
246
|
-
)
|
247
|
-
]
|
248
|
-
|
249
|
-
expected =
|
250
|
-
colored("This is a line", colors[0]) + "\n" +
|
251
|
-
colored("And that's a line", colors[1]) + "\n" +
|
252
|
-
colored("And there's a line too", colors[2]) + "\n"
|
253
|
-
|
254
|
-
actual =
|
255
|
-
colored("This is a line", colors[0]) + "\n" +
|
256
|
-
colored("Something completely different", colors[1]) + "\n" +
|
257
|
-
colored("And there's a line too", colors[2]) + "\n"
|
258
|
-
|
259
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
260
|
-
|
261
|
-
expected_output = <<~STR.strip
|
262
|
-
Differing strings.
|
263
|
-
|
264
|
-
#{
|
265
|
-
colored do
|
266
|
-
expected_line do
|
267
|
-
text "Expected: "
|
268
|
-
text %("\\e[34mThis is a line\\e[0m\\n\\e[38;5;176mAnd that's a line\\e[0m\\n\\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n")
|
269
|
-
end
|
270
|
-
|
271
|
-
actual_line do
|
272
|
-
text " Actual: "
|
273
|
-
text %("\\e[34mThis is a line\\e[0m\\n\\e[38;5;176mSomething completely different\\e[0m\\n\\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n")
|
274
|
-
end
|
275
|
-
end
|
276
|
-
}
|
277
|
-
|
278
|
-
Diff:
|
279
|
-
|
280
|
-
#{
|
281
|
-
colored do
|
282
|
-
plain_line %( \\e[34mThis is a line\\e[0m\\n)
|
283
|
-
expected_line %(- \\e[38;5;176mAnd that's a line\\e[0m\\n)
|
284
|
-
actual_line %(+ \\e[38;5;176mSomething completely different\\e[0m\\n)
|
285
|
-
plain_line %( \\e[38;2;47;59;164mAnd there's a line too\\e[0m\\n)
|
286
|
-
end
|
287
|
-
}
|
288
|
-
STR
|
289
|
-
|
290
|
-
expect(actual_output).to match_output(expected_output)
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
context "given the same array" do
|
295
|
-
it "returns an empty string" do
|
296
|
-
output =
|
297
|
-
described_class.call(
|
298
|
-
expected: %w[sausage egg cheese],
|
299
|
-
actual: %w[sausage egg cheese]
|
300
|
-
)
|
301
|
-
|
302
|
-
expect(output).to eq("")
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context "given two equal-length, one-dimensional arrays with differing numbers" do
|
307
|
-
it "returns a message along with the diff" do
|
308
|
-
actual_output =
|
309
|
-
described_class.call(expected: [1, 2, 3, 4], actual: [1, 2, 99, 4])
|
310
|
-
|
311
|
-
expected_output = <<~STR.strip
|
312
|
-
Differing arrays.
|
313
|
-
|
314
|
-
#{
|
315
|
-
colored do
|
316
|
-
expected_line "Expected: [1, 2, 3, 4]"
|
317
|
-
actual_line " Actual: [1, 2, 99, 4]"
|
318
|
-
end
|
319
|
-
}
|
320
|
-
|
321
|
-
Diff:
|
322
|
-
|
323
|
-
#{
|
324
|
-
colored do
|
325
|
-
plain_line " ["
|
326
|
-
plain_line " 1,"
|
327
|
-
plain_line " 2,"
|
328
|
-
expected_line "- 3,"
|
329
|
-
actual_line "+ 99,"
|
330
|
-
plain_line " 4"
|
331
|
-
plain_line " ]"
|
332
|
-
end
|
333
|
-
}
|
334
|
-
STR
|
335
|
-
|
336
|
-
expect(actual_output).to match_output(expected_output)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
context "given two equal-length, one-dimensional arrays with differing symbols" do
|
341
|
-
it "returns a message along with the diff" do
|
342
|
-
actual_output =
|
343
|
-
described_class.call(
|
344
|
-
expected: %i[one fish two fish],
|
345
|
-
actual: %i[one FISH two fish]
|
346
|
-
)
|
347
|
-
|
348
|
-
expected_output = <<~STR.strip
|
349
|
-
Differing arrays.
|
350
|
-
|
351
|
-
#{
|
352
|
-
colored do
|
353
|
-
expected_line "Expected: [:one, :fish, :two, :fish]"
|
354
|
-
actual_line " Actual: [:one, :FISH, :two, :fish]"
|
355
|
-
end
|
356
|
-
}
|
357
|
-
|
358
|
-
Diff:
|
359
|
-
|
360
|
-
#{
|
361
|
-
colored do
|
362
|
-
plain_line " ["
|
363
|
-
plain_line " :one,"
|
364
|
-
expected_line "- :fish,"
|
365
|
-
actual_line "+ :FISH,"
|
366
|
-
plain_line " :two,"
|
367
|
-
plain_line " :fish"
|
368
|
-
plain_line " ]"
|
369
|
-
end
|
370
|
-
}
|
371
|
-
STR
|
372
|
-
|
373
|
-
expect(actual_output).to match_output(expected_output)
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
context "given two equal-length, one-dimensional arrays with differing strings" do
|
378
|
-
it "returns a message along with the diff" do
|
379
|
-
actual_output =
|
380
|
-
described_class.call(
|
381
|
-
expected: %w[sausage egg cheese],
|
382
|
-
actual: %w[bacon egg cheese]
|
383
|
-
)
|
384
|
-
|
385
|
-
expected_output = <<~STR.strip
|
386
|
-
Differing arrays.
|
387
|
-
|
388
|
-
#{
|
389
|
-
colored do
|
390
|
-
expected_line %(Expected: ["sausage", "egg", "cheese"])
|
391
|
-
actual_line %( Actual: ["bacon", "egg", "cheese"])
|
392
|
-
end
|
393
|
-
}
|
394
|
-
|
395
|
-
Diff:
|
396
|
-
|
397
|
-
#{
|
398
|
-
colored do
|
399
|
-
plain_line " ["
|
400
|
-
expected_line %(- "sausage",)
|
401
|
-
actual_line %(+ "bacon",)
|
402
|
-
plain_line %( "egg",)
|
403
|
-
plain_line %( "cheese")
|
404
|
-
plain_line " ]"
|
405
|
-
end
|
406
|
-
}
|
407
|
-
STR
|
408
|
-
|
409
|
-
expect(actual_output).to match_output(expected_output)
|
410
|
-
end
|
411
|
-
end
|
412
|
-
|
413
|
-
context "given two equal-length, one-dimensional arrays with differing objects" do
|
414
|
-
it "returns a message along with the diff" do
|
415
|
-
actual_output =
|
416
|
-
described_class.call(
|
417
|
-
expected: [
|
418
|
-
SuperDiff::Test::Person.new(name: "Marty", age: 18),
|
419
|
-
SuperDiff::Test::Person.new(name: "Jennifer", age: 17)
|
420
|
-
],
|
421
|
-
actual: [
|
422
|
-
SuperDiff::Test::Person.new(name: "Marty", age: 18),
|
423
|
-
SuperDiff::Test::Person.new(name: "Doc", age: 50)
|
424
|
-
]
|
425
|
-
)
|
426
|
-
|
427
|
-
expected_output = <<~STR.strip
|
428
|
-
Differing arrays.
|
429
|
-
|
430
|
-
#{
|
431
|
-
colored do
|
432
|
-
expected_line %(Expected: [#<SuperDiff::Test::Person name: "Marty", age: 18>, #<SuperDiff::Test::Person name: "Jennifer", age: 17>])
|
433
|
-
actual_line %( Actual: [#<SuperDiff::Test::Person name: "Marty", age: 18>, #<SuperDiff::Test::Person name: "Doc", age: 50>])
|
434
|
-
end
|
435
|
-
}
|
436
|
-
|
437
|
-
Diff:
|
438
|
-
|
439
|
-
#{
|
440
|
-
colored do
|
441
|
-
plain_line " ["
|
442
|
-
plain_line " #<SuperDiff::Test::Person {"
|
443
|
-
plain_line %( name: "Marty",)
|
444
|
-
plain_line " age: 18"
|
445
|
-
plain_line " }>,"
|
446
|
-
plain_line " #<SuperDiff::Test::Person {"
|
447
|
-
expected_line %(- name: "Jennifer",)
|
448
|
-
actual_line %(+ name: "Doc",)
|
449
|
-
expected_line "- age: 17"
|
450
|
-
actual_line "+ age: 50"
|
451
|
-
plain_line " }>"
|
452
|
-
plain_line " ]"
|
453
|
-
end
|
454
|
-
}
|
455
|
-
STR
|
456
|
-
|
457
|
-
expect(actual_output).to match_output(expected_output)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context "given two one-dimensional arrays where the actual has elements added to the end" do
|
462
|
-
it "returns a message along with the diff" do
|
463
|
-
actual_output =
|
464
|
-
described_class.call(expected: ["bread"], actual: %w[bread eggs milk])
|
465
|
-
|
466
|
-
expected_output = <<~STR.strip
|
467
|
-
Differing arrays.
|
468
|
-
|
469
|
-
#{
|
470
|
-
colored do
|
471
|
-
expected_line %(Expected: ["bread"])
|
472
|
-
actual_line %( Actual: ["bread", "eggs", "milk"])
|
473
|
-
end
|
474
|
-
}
|
475
|
-
|
476
|
-
Diff:
|
477
|
-
|
478
|
-
#{
|
479
|
-
colored do
|
480
|
-
plain_line " ["
|
481
|
-
plain_line %( "bread",)
|
482
|
-
actual_line %(+ "eggs",)
|
483
|
-
actual_line %(+ "milk")
|
484
|
-
plain_line " ]"
|
485
|
-
end
|
486
|
-
}
|
487
|
-
STR
|
488
|
-
|
489
|
-
expect(actual_output).to match_output(expected_output)
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
context "given two one-dimensional arrays where the actual has elements missing from the end" do
|
494
|
-
it "returns a message along with the diff" do
|
495
|
-
actual_output =
|
496
|
-
described_class.call(expected: %w[bread eggs milk], actual: ["bread"])
|
497
|
-
|
498
|
-
expected_output = <<~STR.strip
|
499
|
-
Differing arrays.
|
500
|
-
|
501
|
-
#{
|
502
|
-
colored do
|
503
|
-
expected_line %(Expected: ["bread", "eggs", "milk"])
|
504
|
-
actual_line %( Actual: ["bread"])
|
505
|
-
end
|
506
|
-
}
|
507
|
-
|
508
|
-
Diff:
|
509
|
-
|
510
|
-
#{
|
511
|
-
colored do
|
512
|
-
plain_line " ["
|
513
|
-
plain_line %( "bread")
|
514
|
-
expected_line %(- "eggs",)
|
515
|
-
expected_line %(- "milk")
|
516
|
-
plain_line " ]"
|
517
|
-
end
|
518
|
-
}
|
519
|
-
STR
|
520
|
-
|
521
|
-
expect(actual_output).to match_output(expected_output)
|
522
|
-
end
|
523
|
-
end
|
524
|
-
|
525
|
-
context "given two one-dimensional arrays where the actual has elements added to the beginning" do
|
526
|
-
it "returns a message along with the diff" do
|
527
|
-
actual_output =
|
528
|
-
described_class.call(expected: ["milk"], actual: %w[bread eggs milk])
|
529
|
-
|
530
|
-
expected_output = <<~STR.strip
|
531
|
-
Differing arrays.
|
532
|
-
|
533
|
-
#{
|
534
|
-
colored do
|
535
|
-
expected_line %(Expected: ["milk"])
|
536
|
-
actual_line %( Actual: ["bread", "eggs", "milk"])
|
537
|
-
end
|
538
|
-
}
|
539
|
-
|
540
|
-
Diff:
|
541
|
-
|
542
|
-
#{
|
543
|
-
colored do
|
544
|
-
plain_line " ["
|
545
|
-
actual_line %(+ "bread",)
|
546
|
-
actual_line %(+ "eggs",)
|
547
|
-
plain_line %( "milk")
|
548
|
-
plain_line " ]"
|
549
|
-
end
|
550
|
-
}
|
551
|
-
STR
|
552
|
-
|
553
|
-
expect(actual_output).to match_output(expected_output)
|
554
|
-
end
|
555
|
-
end
|
556
|
-
|
557
|
-
context "given two one-dimensional arrays where the actual has elements removed from the beginning" do
|
558
|
-
it "returns a message along with the diff" do
|
559
|
-
actual_output =
|
560
|
-
described_class.call(expected: %w[bread eggs milk], actual: ["milk"])
|
561
|
-
|
562
|
-
expected_output = <<~STR.strip
|
563
|
-
Differing arrays.
|
564
|
-
|
565
|
-
#{
|
566
|
-
colored do
|
567
|
-
expected_line %(Expected: ["bread", "eggs", "milk"])
|
568
|
-
actual_line %( Actual: ["milk"])
|
569
|
-
end
|
570
|
-
}
|
571
|
-
|
572
|
-
Diff:
|
573
|
-
|
574
|
-
#{
|
575
|
-
colored do
|
576
|
-
plain_line " ["
|
577
|
-
expected_line %(- "bread",)
|
578
|
-
expected_line %(- "eggs",)
|
579
|
-
plain_line %( "milk")
|
580
|
-
plain_line " ]"
|
581
|
-
end
|
582
|
-
}
|
583
|
-
STR
|
584
|
-
|
585
|
-
expect(actual_output).to match_output(expected_output)
|
586
|
-
end
|
587
|
-
end
|
588
|
-
|
589
|
-
context "given two arrays containing arrays with differing values" do
|
590
|
-
it "returns a message along with the diff" do
|
591
|
-
actual_output =
|
592
|
-
described_class.call(
|
593
|
-
expected: [1, 2, %i[a b c], 4],
|
594
|
-
actual: [1, 2, %i[a x c], 4]
|
595
|
-
)
|
596
|
-
|
597
|
-
expected_output = <<~STR.strip
|
598
|
-
Differing arrays.
|
599
|
-
|
600
|
-
#{
|
601
|
-
colored do
|
602
|
-
expected_line "Expected: [1, 2, [:a, :b, :c], 4]"
|
603
|
-
actual_line " Actual: [1, 2, [:a, :x, :c], 4]"
|
604
|
-
end
|
605
|
-
}
|
606
|
-
|
607
|
-
Diff:
|
608
|
-
|
609
|
-
#{
|
610
|
-
colored do
|
611
|
-
plain_line " ["
|
612
|
-
plain_line " 1,"
|
613
|
-
plain_line " 2,"
|
614
|
-
plain_line " ["
|
615
|
-
plain_line " :a,"
|
616
|
-
expected_line "- :b,"
|
617
|
-
actual_line "+ :x,"
|
618
|
-
plain_line " :c"
|
619
|
-
plain_line " ],"
|
620
|
-
plain_line " 4"
|
621
|
-
plain_line " ]"
|
622
|
-
end
|
623
|
-
}
|
624
|
-
STR
|
625
|
-
|
626
|
-
expect(actual_output).to match_output(expected_output)
|
627
|
-
end
|
628
|
-
end
|
629
|
-
|
630
|
-
context "given two arrays containing hashes with differing values" do
|
631
|
-
it "returns a message along with the diff" do
|
632
|
-
actual_output =
|
633
|
-
described_class.call(
|
634
|
-
expected: [1, 2, { foo: "bar", baz: "qux" }, 4],
|
635
|
-
actual: [1, 2, { foo: "bar", baz: "qox" }, 4]
|
636
|
-
)
|
637
|
-
|
638
|
-
expected_output = <<~STR.strip
|
639
|
-
Differing arrays.
|
640
|
-
|
641
|
-
#{
|
642
|
-
colored do
|
643
|
-
expected_line %(Expected: [1, 2, { foo: "bar", baz: "qux" }, 4])
|
644
|
-
actual_line %( Actual: [1, 2, { foo: "bar", baz: "qox" }, 4])
|
645
|
-
end
|
646
|
-
}
|
647
|
-
|
648
|
-
Diff:
|
649
|
-
|
650
|
-
#{
|
651
|
-
colored do
|
652
|
-
plain_line " ["
|
653
|
-
plain_line " 1,"
|
654
|
-
plain_line " 2,"
|
655
|
-
plain_line " {"
|
656
|
-
plain_line %( foo: "bar",)
|
657
|
-
expected_line %(- baz: "qux")
|
658
|
-
actual_line %(+ baz: "qox")
|
659
|
-
plain_line " },"
|
660
|
-
plain_line " 4"
|
661
|
-
plain_line " ]"
|
662
|
-
end
|
663
|
-
}
|
664
|
-
STR
|
665
|
-
|
666
|
-
expect(actual_output).to match_output(expected_output)
|
667
|
-
end
|
668
|
-
end
|
669
|
-
|
670
|
-
context "given two arrays containing custom objects with differing attributes" do
|
671
|
-
it "returns a message along with the diff" do
|
672
|
-
actual_output =
|
673
|
-
described_class.call(
|
674
|
-
expected: [
|
675
|
-
1,
|
676
|
-
2,
|
677
|
-
SuperDiff::Test::Person.new(name: "Marty", age: 18),
|
678
|
-
4
|
679
|
-
],
|
680
|
-
actual: [1, 2, SuperDiff::Test::Person.new(name: "Doc", age: 50), 4]
|
681
|
-
)
|
682
|
-
|
683
|
-
expected_output = <<~STR.strip
|
684
|
-
Differing arrays.
|
685
|
-
|
686
|
-
#{
|
687
|
-
colored do
|
688
|
-
expected_line %(Expected: [1, 2, #<SuperDiff::Test::Person name: "Marty", age: 18>, 4])
|
689
|
-
actual_line %( Actual: [1, 2, #<SuperDiff::Test::Person name: "Doc", age: 50>, 4])
|
690
|
-
end
|
691
|
-
}
|
692
|
-
|
693
|
-
Diff:
|
694
|
-
|
695
|
-
#{
|
696
|
-
colored do
|
697
|
-
plain_line " ["
|
698
|
-
plain_line " 1,"
|
699
|
-
plain_line " 2,"
|
700
|
-
plain_line " #<SuperDiff::Test::Person {"
|
701
|
-
expected_line %(- name: "Marty",)
|
702
|
-
actual_line %(+ name: "Doc",)
|
703
|
-
expected_line "- age: 18"
|
704
|
-
actual_line "+ age: 50"
|
705
|
-
plain_line " }>,"
|
706
|
-
plain_line " 4"
|
707
|
-
plain_line " ]"
|
708
|
-
end
|
709
|
-
}
|
710
|
-
STR
|
711
|
-
|
712
|
-
expect(actual_output).to match_output(expected_output)
|
713
|
-
end
|
714
|
-
end
|
715
|
-
|
716
|
-
context "given two arrays which contain all different kinds of values, some which differ" do
|
717
|
-
it "returns a message along with the diff" do
|
718
|
-
actual_output =
|
719
|
-
described_class.call(
|
720
|
-
expected: [
|
721
|
-
[
|
722
|
-
:h1,
|
723
|
-
[:span, [:text, "Hello world"]],
|
724
|
-
{ class: "header", data: { "sticky" => true } }
|
725
|
-
]
|
726
|
-
],
|
727
|
-
actual: [
|
728
|
-
[
|
729
|
-
:h2,
|
730
|
-
[:span, [:text, "Goodbye world"]],
|
731
|
-
{
|
732
|
-
id: "hero",
|
733
|
-
class: "header",
|
734
|
-
data: {
|
735
|
-
"sticky" => false,
|
736
|
-
:role => "deprecated"
|
737
|
-
}
|
738
|
-
}
|
739
|
-
],
|
740
|
-
:br
|
741
|
-
]
|
742
|
-
)
|
743
|
-
|
744
|
-
expected_output = <<~STR.strip
|
745
|
-
Differing arrays.
|
746
|
-
|
747
|
-
#{
|
748
|
-
colored do
|
749
|
-
expected_line %(Expected: [[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true } }]])
|
750
|
-
actual_line %( Actual: [[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, :role => "deprecated" } }], :br])
|
751
|
-
end
|
752
|
-
}
|
753
|
-
|
754
|
-
Diff:
|
755
|
-
|
756
|
-
#{
|
757
|
-
colored do
|
758
|
-
plain_line " ["
|
759
|
-
plain_line " ["
|
760
|
-
expected_line "- :h1,"
|
761
|
-
actual_line "+ :h2,"
|
762
|
-
plain_line " ["
|
763
|
-
plain_line " :span,"
|
764
|
-
plain_line " ["
|
765
|
-
plain_line " :text,"
|
766
|
-
expected_line %(- "Hello world")
|
767
|
-
actual_line %(+ "Goodbye world")
|
768
|
-
plain_line " ]"
|
769
|
-
plain_line " ],"
|
770
|
-
plain_line " {"
|
771
|
-
actual_line %(+ id: "hero",)
|
772
|
-
plain_line %( class: "header",)
|
773
|
-
plain_line " data: {"
|
774
|
-
expected_line %(- "sticky" => true)
|
775
|
-
actual_line %(+ "sticky" => false,)
|
776
|
-
actual_line %(+ :role => "deprecated")
|
777
|
-
plain_line " }"
|
778
|
-
plain_line " }"
|
779
|
-
plain_line " ],"
|
780
|
-
actual_line "+ :br"
|
781
|
-
plain_line " ]"
|
782
|
-
end
|
783
|
-
}
|
784
|
-
STR
|
785
|
-
|
786
|
-
expect(actual_output).to match_output(expected_output)
|
787
|
-
end
|
788
|
-
end
|
789
|
-
|
790
|
-
context "given the same hash" do
|
791
|
-
it "returns an empty string" do
|
792
|
-
output =
|
793
|
-
described_class.call(
|
794
|
-
expected: {
|
795
|
-
name: "Marty"
|
796
|
-
},
|
797
|
-
actual: {
|
798
|
-
name: "Marty"
|
799
|
-
}
|
800
|
-
)
|
801
|
-
|
802
|
-
expect(output).to eq("")
|
803
|
-
end
|
804
|
-
end
|
805
|
-
|
806
|
-
context "given two equal-size, one-dimensional hashes where the same key has differing numbers" do
|
807
|
-
it "returns a message along with the diff" do
|
808
|
-
actual_output =
|
809
|
-
described_class.call(
|
810
|
-
expected: {
|
811
|
-
tall: 12,
|
812
|
-
grande: 19,
|
813
|
-
venti: 20
|
814
|
-
},
|
815
|
-
actual: {
|
816
|
-
tall: 12,
|
817
|
-
grande: 16,
|
818
|
-
venti: 20
|
819
|
-
}
|
820
|
-
)
|
821
|
-
|
822
|
-
expected_output = <<~STR.strip
|
823
|
-
Differing hashes.
|
824
|
-
|
825
|
-
#{
|
826
|
-
colored do
|
827
|
-
expected_line "Expected: { tall: 12, grande: 19, venti: 20 }"
|
828
|
-
actual_line " Actual: { tall: 12, grande: 16, venti: 20 }"
|
829
|
-
end
|
830
|
-
}
|
831
|
-
|
832
|
-
Diff:
|
833
|
-
|
834
|
-
#{
|
835
|
-
colored do
|
836
|
-
plain_line " {"
|
837
|
-
plain_line " tall: 12,"
|
838
|
-
expected_line "- grande: 19,"
|
839
|
-
actual_line "+ grande: 16,"
|
840
|
-
plain_line " venti: 20"
|
841
|
-
plain_line " }"
|
842
|
-
end
|
843
|
-
}
|
844
|
-
STR
|
845
|
-
|
846
|
-
expect(actual_output).to match_output(expected_output)
|
847
|
-
end
|
848
|
-
end
|
849
|
-
|
850
|
-
context "given two equal-size, one-dimensional hashes where keys are strings and the same key has differing numbers" do
|
851
|
-
it "returns a message along with the diff" do
|
852
|
-
actual_output =
|
853
|
-
described_class.call(
|
854
|
-
expected: {
|
855
|
-
"tall" => 12,
|
856
|
-
"grande" => 19,
|
857
|
-
"venti" => 20
|
858
|
-
},
|
859
|
-
actual: {
|
860
|
-
"tall" => 12,
|
861
|
-
"grande" => 16,
|
862
|
-
"venti" => 20
|
863
|
-
}
|
864
|
-
)
|
865
|
-
|
866
|
-
expected_output = <<~STR.strip
|
867
|
-
Differing hashes.
|
868
|
-
|
869
|
-
#{
|
870
|
-
colored do
|
871
|
-
expected_line %(Expected: { "tall" => 12, "grande" => 19, "venti" => 20 })
|
872
|
-
actual_line %( Actual: { "tall" => 12, "grande" => 16, "venti" => 20 })
|
873
|
-
end
|
874
|
-
}
|
875
|
-
|
876
|
-
Diff:
|
877
|
-
|
878
|
-
#{
|
879
|
-
colored do
|
880
|
-
plain_line " {"
|
881
|
-
plain_line %( "tall" => 12,)
|
882
|
-
expected_line %(- "grande" => 19,)
|
883
|
-
actual_line %(+ "grande" => 16,)
|
884
|
-
plain_line %( "venti" => 20)
|
885
|
-
plain_line " }"
|
886
|
-
end
|
887
|
-
}
|
888
|
-
STR
|
889
|
-
|
890
|
-
expect(actual_output).to match_output(expected_output)
|
891
|
-
end
|
892
|
-
end
|
893
|
-
|
894
|
-
context "given two equal-size, one-dimensional hashes where the same key has differing symbols" do
|
895
|
-
it "returns a message along with the diff" do
|
896
|
-
actual_output =
|
897
|
-
described_class.call(
|
898
|
-
expected: {
|
899
|
-
tall: :small,
|
900
|
-
grande: :grand,
|
901
|
-
venti: :large
|
902
|
-
},
|
903
|
-
actual: {
|
904
|
-
tall: :small,
|
905
|
-
grande: :medium,
|
906
|
-
venti: :large
|
907
|
-
}
|
908
|
-
)
|
909
|
-
|
910
|
-
expected_output = <<~STR.strip
|
911
|
-
Differing hashes.
|
912
|
-
|
913
|
-
#{
|
914
|
-
colored do
|
915
|
-
expected_line "Expected: { tall: :small, grande: :grand, venti: :large }"
|
916
|
-
actual_line " Actual: { tall: :small, grande: :medium, venti: :large }"
|
917
|
-
end
|
918
|
-
}
|
919
|
-
|
920
|
-
Diff:
|
921
|
-
|
922
|
-
#{
|
923
|
-
colored do
|
924
|
-
plain_line " {"
|
925
|
-
plain_line " tall: :small,"
|
926
|
-
expected_line "- grande: :grand,"
|
927
|
-
actual_line "+ grande: :medium,"
|
928
|
-
plain_line " venti: :large"
|
929
|
-
plain_line " }"
|
930
|
-
end
|
931
|
-
}
|
932
|
-
STR
|
933
|
-
|
934
|
-
expect(actual_output).to match_output(expected_output)
|
935
|
-
end
|
936
|
-
end
|
937
|
-
|
938
|
-
context "given two equal-size, one-dimensional hashes where the same key has differing strings" do
|
939
|
-
it "returns a message along with the diff" do
|
940
|
-
actual_output =
|
941
|
-
described_class.call(
|
942
|
-
expected: {
|
943
|
-
tall: "small",
|
944
|
-
grande: "grand",
|
945
|
-
venti: "large"
|
946
|
-
},
|
947
|
-
actual: {
|
948
|
-
tall: "small",
|
949
|
-
grande: "medium",
|
950
|
-
venti: "large"
|
951
|
-
}
|
952
|
-
)
|
953
|
-
|
954
|
-
expected_output = <<~STR.strip
|
955
|
-
Differing hashes.
|
956
|
-
|
957
|
-
#{
|
958
|
-
colored do
|
959
|
-
expected_line %(Expected: { tall: "small", grande: "grand", venti: "large" })
|
960
|
-
actual_line %( Actual: { tall: "small", grande: "medium", venti: "large" })
|
961
|
-
end
|
962
|
-
}
|
963
|
-
|
964
|
-
Diff:
|
965
|
-
|
966
|
-
#{
|
967
|
-
colored do
|
968
|
-
plain_line " {"
|
969
|
-
plain_line %( tall: "small",)
|
970
|
-
expected_line %(- grande: "grand",)
|
971
|
-
actual_line %(+ grande: "medium",)
|
972
|
-
plain_line %( venti: "large")
|
973
|
-
plain_line " }"
|
974
|
-
end
|
975
|
-
}
|
976
|
-
STR
|
977
|
-
|
978
|
-
expect(actual_output).to match_output(expected_output)
|
979
|
-
end
|
980
|
-
end
|
981
|
-
|
982
|
-
context "given two equal-size, one-dimensional hashes where the same key has differing objects" do
|
983
|
-
it "returns a message along with the diff" do
|
984
|
-
actual_output =
|
985
|
-
described_class.call(
|
986
|
-
expected: {
|
987
|
-
steve: SuperDiff::Test::Person.new(name: "Jobs", age: 30),
|
988
|
-
susan: SuperDiff::Test::Person.new(name: "Kare", age: 27)
|
989
|
-
},
|
990
|
-
actual: {
|
991
|
-
steve: SuperDiff::Test::Person.new(name: "Wozniak", age: 33),
|
992
|
-
susan: SuperDiff::Test::Person.new(name: "Kare", age: 27)
|
993
|
-
}
|
994
|
-
)
|
995
|
-
|
996
|
-
expected_output = <<~STR.strip
|
997
|
-
Differing hashes.
|
998
|
-
|
999
|
-
#{
|
1000
|
-
colored do
|
1001
|
-
expected_line %(Expected: { steve: #<SuperDiff::Test::Person name: "Jobs", age: 30>, susan: #<SuperDiff::Test::Person name: "Kare", age: 27> })
|
1002
|
-
actual_line %( Actual: { steve: #<SuperDiff::Test::Person name: "Wozniak", age: 33>, susan: #<SuperDiff::Test::Person name: "Kare", age: 27> })
|
1003
|
-
end
|
1004
|
-
}
|
1005
|
-
|
1006
|
-
Diff:
|
1007
|
-
|
1008
|
-
#{
|
1009
|
-
colored do
|
1010
|
-
plain_line " {"
|
1011
|
-
plain_line " steve: #<SuperDiff::Test::Person {"
|
1012
|
-
expected_line %(- name: "Jobs",)
|
1013
|
-
actual_line %(+ name: "Wozniak",)
|
1014
|
-
expected_line "- age: 30"
|
1015
|
-
actual_line "+ age: 33"
|
1016
|
-
plain_line " }>,"
|
1017
|
-
plain_line " susan: #<SuperDiff::Test::Person {"
|
1018
|
-
plain_line %( name: "Kare",)
|
1019
|
-
plain_line " age: 27"
|
1020
|
-
plain_line " }>"
|
1021
|
-
plain_line " }"
|
1022
|
-
end
|
1023
|
-
}
|
1024
|
-
STR
|
1025
|
-
|
1026
|
-
expect(actual_output).to match_output(expected_output)
|
1027
|
-
end
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
context "given two equal-size, one-dimensional hashes where the actual has extra keys" do
|
1031
|
-
it "returns a message along with the diff" do
|
1032
|
-
actual_output =
|
1033
|
-
described_class.call(
|
1034
|
-
expected: {
|
1035
|
-
latte: 4.5
|
1036
|
-
},
|
1037
|
-
actual: {
|
1038
|
-
latte: 4.5,
|
1039
|
-
mocha: 3.5,
|
1040
|
-
cortado: 3
|
1041
|
-
}
|
1042
|
-
)
|
1043
|
-
|
1044
|
-
expected_output = <<~STR.strip
|
1045
|
-
Differing hashes.
|
1046
|
-
|
1047
|
-
#{
|
1048
|
-
colored do
|
1049
|
-
expected_line "Expected: { latte: 4.5 }"
|
1050
|
-
actual_line " Actual: { latte: 4.5, mocha: 3.5, cortado: 3 }"
|
1051
|
-
end
|
1052
|
-
}
|
1053
|
-
|
1054
|
-
Diff:
|
1055
|
-
|
1056
|
-
#{
|
1057
|
-
colored do
|
1058
|
-
plain_line " {"
|
1059
|
-
plain_line " latte: 4.5,"
|
1060
|
-
actual_line "+ mocha: 3.5,"
|
1061
|
-
actual_line "+ cortado: 3"
|
1062
|
-
plain_line " }"
|
1063
|
-
end
|
1064
|
-
}
|
1065
|
-
STR
|
1066
|
-
|
1067
|
-
expect(actual_output).to match_output(expected_output)
|
1068
|
-
end
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
context "given two equal-size, one-dimensional hashes where the actual has missing keys" do
|
1072
|
-
it "returns a message along with the diff" do
|
1073
|
-
actual_output =
|
1074
|
-
described_class.call(
|
1075
|
-
expected: {
|
1076
|
-
latte: 4.5,
|
1077
|
-
mocha: 3.5,
|
1078
|
-
cortado: 3
|
1079
|
-
},
|
1080
|
-
actual: {
|
1081
|
-
latte: 4.5
|
1082
|
-
}
|
1083
|
-
)
|
1084
|
-
|
1085
|
-
expected_output = <<~STR.strip
|
1086
|
-
Differing hashes.
|
1087
|
-
|
1088
|
-
#{
|
1089
|
-
colored do
|
1090
|
-
expected_line "Expected: { latte: 4.5, mocha: 3.5, cortado: 3 }"
|
1091
|
-
actual_line " Actual: { latte: 4.5 }"
|
1092
|
-
end
|
1093
|
-
}
|
1094
|
-
|
1095
|
-
Diff:
|
1096
|
-
|
1097
|
-
#{
|
1098
|
-
colored do
|
1099
|
-
plain_line " {"
|
1100
|
-
plain_line " latte: 4.5"
|
1101
|
-
expected_line "- mocha: 3.5,"
|
1102
|
-
expected_line "- cortado: 3"
|
1103
|
-
plain_line " }"
|
1104
|
-
end
|
1105
|
-
}
|
1106
|
-
STR
|
1107
|
-
|
1108
|
-
expect(actual_output).to match_output(expected_output)
|
1109
|
-
end
|
1110
|
-
end
|
1111
|
-
|
1112
|
-
context "given two equal-size, one-dimensional hashes where there is a mixture of missing and extra keys in relatively the same order" do
|
1113
|
-
context "and the actual value is in relatively the same order as the expected" do
|
1114
|
-
it "preserves the order of the keys as they are defined" do
|
1115
|
-
actual_output =
|
1116
|
-
described_class.call(
|
1117
|
-
expected: {
|
1118
|
-
listed_count: 37_009,
|
1119
|
-
created_at: "Tue Jan 13 19:28:24 +0000 2009",
|
1120
|
-
favourites_count: 38,
|
1121
|
-
geo_enabled: false,
|
1122
|
-
verified: true,
|
1123
|
-
statuses_count: 273_860,
|
1124
|
-
media_count: 51_044,
|
1125
|
-
contributors_enabled: false,
|
1126
|
-
profile_background_color: "FFF1E0",
|
1127
|
-
profile_background_image_url_https:
|
1128
|
-
"https://abs.twimg.com/images/themes/theme1/bg.png",
|
1129
|
-
profile_background_tile: false,
|
1130
|
-
profile_image_url:
|
1131
|
-
"http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
|
1132
|
-
profile_image_url_https:
|
1133
|
-
"https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
|
1134
|
-
profile_banner_url:
|
1135
|
-
"https://pbs.twimg.com/profile_banners/18949452/1581526592"
|
1136
|
-
},
|
1137
|
-
actual: {
|
1138
|
-
listed_count: 37_009,
|
1139
|
-
created_at: "Tue Jan 13 19:28:24 +0000 2009",
|
1140
|
-
favourites_count: 38,
|
1141
|
-
utc_offset: nil,
|
1142
|
-
time_zone: nil,
|
1143
|
-
statuses_count: 273_860,
|
1144
|
-
media_count: 51_044,
|
1145
|
-
contributors_enabled: false,
|
1146
|
-
is_translator: false,
|
1147
|
-
is_translation_enabled: false,
|
1148
|
-
profile_background_color: "FFF1E0",
|
1149
|
-
profile_background_image_url_https:
|
1150
|
-
"https://abs.twimg.com/images/themes/theme1/bg.png",
|
1151
|
-
profile_background_tile: false,
|
1152
|
-
profile_banner_url:
|
1153
|
-
"https://pbs.twimg.com/profile_banners/18949452/1581526592"
|
1154
|
-
}
|
1155
|
-
)
|
1156
|
-
|
1157
|
-
expected_output = <<~STR.strip
|
1158
|
-
Differing hashes.
|
1159
|
-
|
1160
|
-
#{
|
1161
|
-
colored do
|
1162
|
-
expected_line %(Expected: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
|
1163
|
-
actual_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
|
1164
|
-
end
|
1165
|
-
}
|
1166
|
-
|
1167
|
-
Diff:
|
1168
|
-
|
1169
|
-
#{
|
1170
|
-
colored do
|
1171
|
-
plain_line " {"
|
1172
|
-
plain_line " listed_count: 37009,"
|
1173
|
-
plain_line %( created_at: "Tue Jan 13 19:28:24 +0000 2009",)
|
1174
|
-
plain_line " favourites_count: 38,"
|
1175
|
-
expected_line "- geo_enabled: false,"
|
1176
|
-
expected_line "- verified: true,"
|
1177
|
-
actual_line "+ utc_offset: nil,"
|
1178
|
-
actual_line "+ time_zone: nil,"
|
1179
|
-
plain_line " statuses_count: 273860,"
|
1180
|
-
plain_line " media_count: 51044,"
|
1181
|
-
plain_line " contributors_enabled: false,"
|
1182
|
-
actual_line "+ is_translator: false,"
|
1183
|
-
actual_line "+ is_translation_enabled: false,"
|
1184
|
-
plain_line %( profile_background_color: "FFF1E0",)
|
1185
|
-
plain_line %( profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",)
|
1186
|
-
plain_line " profile_background_tile: false,"
|
1187
|
-
expected_line %(- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
|
1188
|
-
expected_line %(- profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
|
1189
|
-
plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592")
|
1190
|
-
plain_line " }"
|
1191
|
-
end
|
1192
|
-
}
|
1193
|
-
STR
|
1194
|
-
|
1195
|
-
expect(actual_output).to match_output(expected_output)
|
1196
|
-
end
|
1197
|
-
end
|
1198
|
-
|
1199
|
-
context "and the actual value is in a different order than the expected" do
|
1200
|
-
it "preserves the order of the keys as they are defined" do
|
1201
|
-
actual_output =
|
1202
|
-
described_class.call(
|
1203
|
-
expected: {
|
1204
|
-
created_at: "Tue Jan 13 19:28:24 +0000 2009",
|
1205
|
-
favourites_count: 38,
|
1206
|
-
geo_enabled: false,
|
1207
|
-
verified: true,
|
1208
|
-
media_count: 51_044,
|
1209
|
-
statuses_count: 273_860,
|
1210
|
-
contributors_enabled: false,
|
1211
|
-
profile_background_image_url_https:
|
1212
|
-
"https://abs.twimg.com/images/themes/theme1/bg.png",
|
1213
|
-
profile_background_color: "FFF1E0",
|
1214
|
-
profile_background_tile: false,
|
1215
|
-
profile_image_url:
|
1216
|
-
"http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
|
1217
|
-
listed_count: 37_009,
|
1218
|
-
profile_banner_url:
|
1219
|
-
"https://pbs.twimg.com/profile_banners/18949452/1581526592"
|
1220
|
-
},
|
1221
|
-
actual: {
|
1222
|
-
listed_count: 37_009,
|
1223
|
-
created_at: "Tue Jan 13 19:28:24 +0000 2009",
|
1224
|
-
favourites_count: 38,
|
1225
|
-
utc_offset: nil,
|
1226
|
-
statuses_count: 273_860,
|
1227
|
-
media_count: 51_044,
|
1228
|
-
contributors_enabled: false,
|
1229
|
-
is_translator: false,
|
1230
|
-
is_translation_enabled: false,
|
1231
|
-
profile_background_color: "FFF1E0",
|
1232
|
-
profile_background_image_url_https:
|
1233
|
-
"https://abs.twimg.com/images/themes/theme1/bg.png",
|
1234
|
-
profile_banner_url:
|
1235
|
-
"https://pbs.twimg.com/profile_banners/18949452/1581526592",
|
1236
|
-
profile_background_tile: false
|
1237
|
-
}
|
1238
|
-
)
|
1239
|
-
|
1240
|
-
expected_output = <<~STR.strip
|
1241
|
-
Differing hashes.
|
1242
|
-
|
1243
|
-
#{
|
1244
|
-
colored do
|
1245
|
-
expected_line %(Expected: { created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, media_count: 51044, statuses_count: 273860, contributors_enabled: false, profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_color: "FFF1E0", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", listed_count: 37009, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
|
1246
|
-
actual_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_background_tile: false })
|
1247
|
-
end
|
1248
|
-
}
|
1249
|
-
|
1250
|
-
Diff:
|
1251
|
-
|
1252
|
-
#{
|
1253
|
-
colored do
|
1254
|
-
plain_line " {"
|
1255
|
-
plain_line " listed_count: 37009,"
|
1256
|
-
plain_line %( created_at: "Tue Jan 13 19:28:24 +0000 2009",)
|
1257
|
-
plain_line " favourites_count: 38,"
|
1258
|
-
expected_line "- geo_enabled: false,"
|
1259
|
-
expected_line "- verified: true,"
|
1260
|
-
actual_line "+ utc_offset: nil,"
|
1261
|
-
plain_line " statuses_count: 273860,"
|
1262
|
-
plain_line " media_count: 51044,"
|
1263
|
-
plain_line " contributors_enabled: false,"
|
1264
|
-
actual_line "+ is_translator: false,"
|
1265
|
-
actual_line "+ is_translation_enabled: false,"
|
1266
|
-
plain_line %( profile_background_color: "FFF1E0",)
|
1267
|
-
plain_line %( profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",)
|
1268
|
-
expected_line %(- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
|
1269
|
-
plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",)
|
1270
|
-
plain_line " profile_background_tile: false"
|
1271
|
-
plain_line " }"
|
1272
|
-
end
|
1273
|
-
}
|
1274
|
-
STR
|
1275
|
-
|
1276
|
-
expect(actual_output).to match_output(expected_output)
|
1277
|
-
end
|
1278
|
-
end
|
1279
|
-
end
|
1280
|
-
|
1281
|
-
context "given two hashes containing arrays with differing values" do
|
1282
|
-
it "returns a message along with the diff" do
|
1283
|
-
actual_output =
|
1284
|
-
described_class.call(
|
1285
|
-
expected: {
|
1286
|
-
name: "Elliot",
|
1287
|
-
interests: %w[music football programming],
|
1288
|
-
age: 30
|
1289
|
-
},
|
1290
|
-
actual: {
|
1291
|
-
name: "Elliot",
|
1292
|
-
interests: %w[music travel programming],
|
1293
|
-
age: 30
|
1294
|
-
}
|
1295
|
-
)
|
1296
|
-
|
1297
|
-
expected_output = <<~STR.strip
|
1298
|
-
Differing hashes.
|
1299
|
-
|
1300
|
-
#{
|
1301
|
-
colored do
|
1302
|
-
expected_line %(Expected: { name: "Elliot", interests: ["music", "football", "programming"], age: 30 })
|
1303
|
-
actual_line %( Actual: { name: "Elliot", interests: ["music", "travel", "programming"], age: 30 })
|
1304
|
-
end
|
1305
|
-
}
|
1306
|
-
|
1307
|
-
Diff:
|
1308
|
-
|
1309
|
-
#{
|
1310
|
-
colored do
|
1311
|
-
plain_line " {"
|
1312
|
-
plain_line %( name: "Elliot",)
|
1313
|
-
plain_line " interests: ["
|
1314
|
-
plain_line %( "music",)
|
1315
|
-
expected_line %(- "football",)
|
1316
|
-
actual_line %(+ "travel",)
|
1317
|
-
plain_line %( "programming")
|
1318
|
-
plain_line " ],"
|
1319
|
-
plain_line " age: 30"
|
1320
|
-
plain_line " }"
|
1321
|
-
end
|
1322
|
-
}
|
1323
|
-
STR
|
1324
|
-
|
1325
|
-
expect(actual_output).to match_output(expected_output)
|
1326
|
-
end
|
1327
|
-
end
|
1328
|
-
|
1329
|
-
context "given two hashes containing hashes with differing values" do
|
1330
|
-
it "returns a message along with the diff" do
|
1331
|
-
actual_output =
|
1332
|
-
described_class.call(
|
1333
|
-
expected: {
|
1334
|
-
check_spelling: true,
|
1335
|
-
substitutions: {
|
1336
|
-
"YOLO" => "You only live once",
|
1337
|
-
"BRB" => "Buns, ribs, and bacon",
|
1338
|
-
"YMMV" => "Your mileage may vary"
|
1339
|
-
},
|
1340
|
-
check_grammar: false
|
1341
|
-
},
|
1342
|
-
actual: {
|
1343
|
-
check_spelling: true,
|
1344
|
-
substitutions: {
|
1345
|
-
"YOLO" => "You only live once",
|
1346
|
-
"BRB" => "Be right back",
|
1347
|
-
"YMMV" => "Your mileage may vary"
|
1348
|
-
},
|
1349
|
-
check_grammar: false
|
1350
|
-
}
|
1351
|
-
)
|
1352
|
-
|
1353
|
-
expected_output = <<~STR.strip
|
1354
|
-
Differing hashes.
|
1355
|
-
|
1356
|
-
#{
|
1357
|
-
colored do
|
1358
|
-
expected_line %(Expected: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Buns, ribs, and bacon", "YMMV" => "Your mileage may vary" }, check_grammar: false })
|
1359
|
-
actual_line %( Actual: { check_spelling: true, substitutions: { "YOLO" => "You only live once", "BRB" => "Be right back", "YMMV" => "Your mileage may vary" }, check_grammar: false })
|
1360
|
-
end
|
1361
|
-
}
|
1362
|
-
|
1363
|
-
Diff:
|
1364
|
-
|
1365
|
-
#{
|
1366
|
-
colored do
|
1367
|
-
plain_line " {"
|
1368
|
-
plain_line " check_spelling: true,"
|
1369
|
-
plain_line " substitutions: {"
|
1370
|
-
plain_line %( "YOLO" => "You only live once",)
|
1371
|
-
expected_line %(- "BRB" => "Buns, ribs, and bacon",)
|
1372
|
-
actual_line %(+ "BRB" => "Be right back",)
|
1373
|
-
plain_line %( "YMMV" => "Your mileage may vary")
|
1374
|
-
plain_line " },"
|
1375
|
-
plain_line " check_grammar: false"
|
1376
|
-
plain_line " }"
|
1377
|
-
end
|
1378
|
-
}
|
1379
|
-
STR
|
1380
|
-
|
1381
|
-
expect(actual_output).to match_output(expected_output)
|
1382
|
-
end
|
1383
|
-
end
|
1384
|
-
|
1385
|
-
context "given two hashes containing custom objects with differing attributes" do
|
1386
|
-
it "returns a message along with the diff" do
|
1387
|
-
actual_output =
|
1388
|
-
described_class.call(
|
1389
|
-
expected: {
|
1390
|
-
order_id: 1234,
|
1391
|
-
person: SuperDiff::Test::Person.new(name: "Marty", age: 18),
|
1392
|
-
amount: 350_00
|
1393
|
-
},
|
1394
|
-
actual: {
|
1395
|
-
order_id: 1234,
|
1396
|
-
person: SuperDiff::Test::Person.new(name: "Doc", age: 50),
|
1397
|
-
amount: 350_00
|
1398
|
-
}
|
1399
|
-
)
|
1400
|
-
|
1401
|
-
expected_output = <<~STR.strip
|
1402
|
-
Differing hashes.
|
1403
|
-
|
1404
|
-
#{
|
1405
|
-
colored do
|
1406
|
-
expected_line %(Expected: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Marty", age: 18>, amount: 35000 })
|
1407
|
-
actual_line %( Actual: { order_id: 1234, person: #<SuperDiff::Test::Person name: "Doc", age: 50>, amount: 35000 })
|
1408
|
-
end
|
1409
|
-
}
|
1410
|
-
|
1411
|
-
Diff:
|
1412
|
-
|
1413
|
-
#{
|
1414
|
-
colored do
|
1415
|
-
plain_line " {"
|
1416
|
-
plain_line " order_id: 1234,"
|
1417
|
-
plain_line " person: #<SuperDiff::Test::Person {"
|
1418
|
-
expected_line %(- name: "Marty",)
|
1419
|
-
actual_line %(+ name: "Doc",)
|
1420
|
-
expected_line "- age: 18"
|
1421
|
-
actual_line "+ age: 50"
|
1422
|
-
plain_line " }>,"
|
1423
|
-
plain_line " amount: 35000"
|
1424
|
-
plain_line " }"
|
1425
|
-
end
|
1426
|
-
}
|
1427
|
-
STR
|
1428
|
-
|
1429
|
-
expect(actual_output).to match_output(expected_output)
|
1430
|
-
end
|
1431
|
-
end
|
1432
|
-
|
1433
|
-
context "given two hashes which contain all different kinds of values, some which differ" do
|
1434
|
-
it "returns a message along with the diff" do
|
1435
|
-
actual_output =
|
1436
|
-
described_class.call(
|
1437
|
-
expected: {
|
1438
|
-
customer: {
|
1439
|
-
name: "Marty McFly",
|
1440
|
-
shipping_address: {
|
1441
|
-
line_1: "123 Main St.",
|
1442
|
-
city: "Hill Valley",
|
1443
|
-
state: "CA",
|
1444
|
-
zip: "90382"
|
1445
|
-
}
|
1446
|
-
},
|
1447
|
-
items: [
|
1448
|
-
{
|
1449
|
-
name: "Fender Stratocaster",
|
1450
|
-
cost: 100_000,
|
1451
|
-
options: %w[red blue green]
|
1452
|
-
},
|
1453
|
-
{ name: "Chevy 4x4" }
|
1454
|
-
]
|
1455
|
-
},
|
1456
|
-
actual: {
|
1457
|
-
customer: {
|
1458
|
-
name: "Marty McFly, Jr.",
|
1459
|
-
shipping_address: {
|
1460
|
-
line_1: "456 Ponderosa Ct.",
|
1461
|
-
city: "Hill Valley",
|
1462
|
-
state: "CA",
|
1463
|
-
zip: "90382"
|
1464
|
-
}
|
1465
|
-
},
|
1466
|
-
items: [
|
1467
|
-
{
|
1468
|
-
name: "Fender Stratocaster",
|
1469
|
-
cost: 100_000,
|
1470
|
-
options: %w[red blue green]
|
1471
|
-
},
|
1472
|
-
{ name: "Mattel Hoverboard" }
|
1473
|
-
]
|
1474
|
-
}
|
1475
|
-
)
|
1476
|
-
|
1477
|
-
expected_output = <<~STR.strip
|
1478
|
-
Differing hashes.
|
1479
|
-
|
1480
|
-
#{
|
1481
|
-
colored do
|
1482
|
-
expected_line %(Expected: { customer: { name: "Marty McFly", shipping_address: { line_1: "123 Main St.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Chevy 4x4" }] })
|
1483
|
-
actual_line %( Actual: { customer: { name: "Marty McFly, Jr.", shipping_address: { line_1: "456 Ponderosa Ct.", city: "Hill Valley", state: "CA", zip: "90382" } }, items: [{ name: "Fender Stratocaster", cost: 100000, options: ["red", "blue", "green"] }, { name: "Mattel Hoverboard" }] })
|
1484
|
-
end
|
1485
|
-
}
|
1486
|
-
|
1487
|
-
Diff:
|
1488
|
-
|
1489
|
-
#{
|
1490
|
-
colored do
|
1491
|
-
plain_line " {"
|
1492
|
-
plain_line " customer: {"
|
1493
|
-
expected_line %(- name: "Marty McFly",)
|
1494
|
-
actual_line %(+ name: "Marty McFly, Jr.",)
|
1495
|
-
plain_line " shipping_address: {"
|
1496
|
-
expected_line %(- line_1: "123 Main St.",)
|
1497
|
-
actual_line %(+ line_1: "456 Ponderosa Ct.",)
|
1498
|
-
plain_line %( city: "Hill Valley",)
|
1499
|
-
plain_line %( state: "CA",)
|
1500
|
-
plain_line %( zip: "90382")
|
1501
|
-
plain_line " }"
|
1502
|
-
plain_line " },"
|
1503
|
-
plain_line " items: ["
|
1504
|
-
plain_line " {"
|
1505
|
-
plain_line %( name: "Fender Stratocaster",)
|
1506
|
-
plain_line " cost: 100000,"
|
1507
|
-
plain_line " options: ["
|
1508
|
-
plain_line %( "red",)
|
1509
|
-
plain_line %( "blue",)
|
1510
|
-
plain_line %( "green")
|
1511
|
-
plain_line " ]"
|
1512
|
-
plain_line " },"
|
1513
|
-
plain_line " {"
|
1514
|
-
expected_line %(- name: "Chevy 4x4")
|
1515
|
-
actual_line %(+ name: "Mattel Hoverboard")
|
1516
|
-
plain_line " }"
|
1517
|
-
plain_line " ]"
|
1518
|
-
plain_line " }"
|
1519
|
-
end
|
1520
|
-
}
|
1521
|
-
STR
|
1522
|
-
|
1523
|
-
expect(actual_output).to match_output(expected_output)
|
1524
|
-
end
|
1525
|
-
end
|
1526
|
-
|
1527
|
-
context "given two custom objects which == each other" do
|
1528
|
-
it "returns an empty string" do
|
1529
|
-
expected = SuperDiff::Test::Person.new(name: "Marty", age: 18)
|
1530
|
-
actual = SuperDiff::Test::Person.new(name: "Marty", age: 18)
|
1531
|
-
|
1532
|
-
output = described_class.call(expected: expected, actual: actual)
|
1533
|
-
|
1534
|
-
expect(output).to eq("")
|
1535
|
-
end
|
1536
|
-
end
|
1537
|
-
|
1538
|
-
context "given two different versions of the same custom class" do
|
1539
|
-
it "returns a message along with a comparison" do
|
1540
|
-
expected = SuperDiff::Test::Person.new(name: "Marty", age: 18)
|
1541
|
-
actual = SuperDiff::Test::Person.new(name: "Doc", age: 50)
|
1542
|
-
|
1543
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1544
|
-
|
1545
|
-
expected_output = <<~STR.strip
|
1546
|
-
Differing objects.
|
1547
|
-
|
1548
|
-
#{
|
1549
|
-
colored do
|
1550
|
-
expected_line %(Expected: #<SuperDiff::Test::Person name: "Marty", age: 18>)
|
1551
|
-
actual_line %( Actual: #<SuperDiff::Test::Person name: "Doc", age: 50>)
|
1552
|
-
end
|
1553
|
-
}
|
1554
|
-
|
1555
|
-
Diff:
|
1556
|
-
|
1557
|
-
#{
|
1558
|
-
colored do
|
1559
|
-
plain_line " #<SuperDiff::Test::Person {"
|
1560
|
-
expected_line %(- name: "Marty",)
|
1561
|
-
actual_line %(+ name: "Doc",)
|
1562
|
-
expected_line "- age: 18"
|
1563
|
-
actual_line "+ age: 50"
|
1564
|
-
plain_line " }>"
|
1565
|
-
end
|
1566
|
-
}
|
1567
|
-
STR
|
1568
|
-
|
1569
|
-
expect(actual_output).to match_output(expected_output)
|
1570
|
-
end
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
context "given two different versions of the same non-custom class" do
|
1574
|
-
it "returns a message along with the diff" do
|
1575
|
-
expected =
|
1576
|
-
SuperDiff::Test::Player.new(
|
1577
|
-
handle: "martymcfly",
|
1578
|
-
character: "mirage",
|
1579
|
-
inventory: ["flatline", "purple body shield"],
|
1580
|
-
shields: 0.6,
|
1581
|
-
health: 0.3,
|
1582
|
-
ultimate: 0.8
|
1583
|
-
)
|
1584
|
-
actual =
|
1585
|
-
SuperDiff::Test::Player.new(
|
1586
|
-
handle: "docbrown",
|
1587
|
-
character: "lifeline",
|
1588
|
-
inventory: %w[wingman mastiff],
|
1589
|
-
shields: 0.6,
|
1590
|
-
health: 0.3,
|
1591
|
-
ultimate: 0.8
|
1592
|
-
)
|
1593
|
-
|
1594
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1595
|
-
|
1596
|
-
expected_output = <<~STR.strip
|
1597
|
-
Differing objects.
|
1598
|
-
|
1599
|
-
#{
|
1600
|
-
colored do
|
1601
|
-
expected_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Core::Helpers.object_address_for(expected)} @character="mirage", @handle="martymcfly", @health=0.3, @inventory=["flatline", "purple body shield"], @shields=0.6, @ultimate=0.8>)
|
1602
|
-
actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Core::Helpers.object_address_for(actual)} @character="lifeline", @handle="docbrown", @health=0.3, @inventory=["wingman", "mastiff"], @shields=0.6, @ultimate=0.8>)
|
1603
|
-
end
|
1604
|
-
}
|
1605
|
-
|
1606
|
-
Diff:
|
1607
|
-
|
1608
|
-
#{
|
1609
|
-
colored do
|
1610
|
-
plain_line %( #<SuperDiff::Test::Player:#{SuperDiff::Core::Helpers.object_address_for(actual)} {)
|
1611
|
-
expected_line %(- @character="mirage",)
|
1612
|
-
actual_line %(+ @character="lifeline",)
|
1613
|
-
expected_line %(- @handle="martymcfly",)
|
1614
|
-
actual_line %(+ @handle="docbrown",)
|
1615
|
-
plain_line " @health=0.3,"
|
1616
|
-
plain_line " @inventory=["
|
1617
|
-
expected_line %(- "flatline",)
|
1618
|
-
actual_line %(+ "wingman",)
|
1619
|
-
expected_line %(- "purple body shield")
|
1620
|
-
actual_line %(+ "mastiff")
|
1621
|
-
plain_line " ],"
|
1622
|
-
plain_line " @shields=0.6,"
|
1623
|
-
plain_line " @ultimate=0.8"
|
1624
|
-
plain_line " }>"
|
1625
|
-
end
|
1626
|
-
}
|
1627
|
-
STR
|
1628
|
-
|
1629
|
-
expect(actual_output).to match_output(expected_output)
|
1630
|
-
end
|
1631
|
-
end
|
1632
|
-
|
1633
|
-
context "given two completely different kinds of custom objects" do
|
1634
|
-
it "returns a message along with the diff" do
|
1635
|
-
expected = SuperDiff::Test::Person.new(name: "Marty", age: 31)
|
1636
|
-
actual =
|
1637
|
-
SuperDiff::Test::Customer.new(
|
1638
|
-
name: "Doc",
|
1639
|
-
shipping_address: :some_shipping_address,
|
1640
|
-
phone: "1234567890"
|
1641
|
-
)
|
1642
|
-
|
1643
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1644
|
-
|
1645
|
-
expected_output = <<~STR.strip
|
1646
|
-
Differing objects.
|
1647
|
-
|
1648
|
-
#{
|
1649
|
-
colored do
|
1650
|
-
expected_line %(Expected: #<SuperDiff::Test::Person name: "Marty", age: 31>)
|
1651
|
-
actual_line %( Actual: #<SuperDiff::Test::Customer name: "Doc", shipping_address: :some_shipping_address, phone: "1234567890">)
|
1652
|
-
end
|
1653
|
-
}
|
1654
|
-
STR
|
1655
|
-
|
1656
|
-
expect(actual_output).to match_output(expected_output)
|
1657
|
-
end
|
1658
|
-
end
|
1659
|
-
|
1660
|
-
context "given two completely different kinds of non-custom objects" do
|
1661
|
-
it "returns a message along with the diff" do
|
1662
|
-
expected = SuperDiff::Test::Item.new(name: "camera", quantity: 3)
|
1663
|
-
actual =
|
1664
|
-
SuperDiff::Test::Player.new(
|
1665
|
-
handle: "mcmire",
|
1666
|
-
character: "Jon",
|
1667
|
-
inventory: ["sword"],
|
1668
|
-
shields: 11.4,
|
1669
|
-
health: 4,
|
1670
|
-
ultimate: true
|
1671
|
-
)
|
1672
|
-
|
1673
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1674
|
-
|
1675
|
-
expected_output = <<~STR.strip
|
1676
|
-
Differing objects.
|
1677
|
-
|
1678
|
-
#{
|
1679
|
-
colored do
|
1680
|
-
expected_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Core::Helpers.object_address_for(expected)} @name="camera", @quantity=3>)
|
1681
|
-
actual_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Core::Helpers.object_address_for(actual)} @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>)
|
1682
|
-
end
|
1683
|
-
}
|
1684
|
-
STR
|
1685
|
-
|
1686
|
-
expect(actual_output).to match_output(expected_output)
|
1687
|
-
end
|
1688
|
-
end
|
1689
|
-
|
1690
|
-
context "when the expected value is a data structure that refers to itself somewhere inside of it" do
|
1691
|
-
it "replaces the reference with ∙∙∙" do
|
1692
|
-
expected = %w[a b c]
|
1693
|
-
expected.insert(1, expected)
|
1694
|
-
actual = %w[a x b c]
|
1695
|
-
|
1696
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1697
|
-
|
1698
|
-
expected_output = <<~STR.strip
|
1699
|
-
Differing arrays.
|
1700
|
-
|
1701
|
-
#{
|
1702
|
-
colored do
|
1703
|
-
expected_line %(Expected: ["a", ∙∙∙, "b", "c"])
|
1704
|
-
actual_line %( Actual: ["a", "x", "b", "c"])
|
1705
|
-
end
|
1706
|
-
}
|
1707
|
-
|
1708
|
-
Diff:
|
1709
|
-
|
1710
|
-
#{
|
1711
|
-
colored do
|
1712
|
-
plain_line " ["
|
1713
|
-
plain_line %( "a",)
|
1714
|
-
expected_line "- ∙∙∙,"
|
1715
|
-
actual_line %(+ "x",)
|
1716
|
-
plain_line %( "b",)
|
1717
|
-
plain_line %( "c")
|
1718
|
-
plain_line " ]"
|
1719
|
-
end
|
1720
|
-
}
|
1721
|
-
STR
|
1722
|
-
|
1723
|
-
expect(actual_output).to match_output(expected_output)
|
1724
|
-
end
|
1725
|
-
end
|
1726
|
-
|
1727
|
-
context "when the actual value is a data structure that refers to itself somewhere inside of it" do
|
1728
|
-
it "replaces the reference with ∙∙∙" do
|
1729
|
-
expected = %w[a x b c]
|
1730
|
-
actual = %w[a b c]
|
1731
|
-
actual.insert(1, actual)
|
1732
|
-
|
1733
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1734
|
-
|
1735
|
-
expected_output = <<~STR.strip
|
1736
|
-
Differing arrays.
|
1737
|
-
|
1738
|
-
#{
|
1739
|
-
colored do
|
1740
|
-
expected_line %(Expected: ["a", "x", "b", "c"])
|
1741
|
-
actual_line %( Actual: ["a", ∙∙∙, "b", "c"])
|
1742
|
-
end
|
1743
|
-
}
|
1744
|
-
|
1745
|
-
Diff:
|
1746
|
-
|
1747
|
-
#{
|
1748
|
-
colored do
|
1749
|
-
plain_line " ["
|
1750
|
-
plain_line %( "a",)
|
1751
|
-
expected_line %(- "x",)
|
1752
|
-
actual_line "+ ∙∙∙,"
|
1753
|
-
plain_line %( "b",)
|
1754
|
-
plain_line %( "c")
|
1755
|
-
plain_line " ]"
|
1756
|
-
end
|
1757
|
-
}
|
1758
|
-
STR
|
1759
|
-
|
1760
|
-
expect(actual_output).to match_output(expected_output)
|
1761
|
-
end
|
1762
|
-
end
|
1763
|
-
|
1764
|
-
context "when the data structure being different is present inside a secondary layer" do
|
1765
|
-
it "replaces the reference with ∙∙∙" do
|
1766
|
-
expected = { foo: %w[a x b c] }
|
1767
|
-
actual = { foo: %w[a b c] }
|
1768
|
-
actual[:foo].insert(1, actual)
|
1769
|
-
|
1770
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1771
|
-
|
1772
|
-
expected_output = <<~STR.strip
|
1773
|
-
Differing hashes.
|
1774
|
-
|
1775
|
-
#{
|
1776
|
-
colored do
|
1777
|
-
expected_line %(Expected: { foo: ["a", "x", "b", "c"] })
|
1778
|
-
actual_line %( Actual: { foo: ["a", ∙∙∙, "b", "c"] })
|
1779
|
-
end
|
1780
|
-
}
|
1781
|
-
|
1782
|
-
Diff:
|
1783
|
-
|
1784
|
-
#{
|
1785
|
-
colored do
|
1786
|
-
plain_line " {"
|
1787
|
-
plain_line " foo: ["
|
1788
|
-
plain_line %( "a",)
|
1789
|
-
expected_line %(- "x",)
|
1790
|
-
actual_line "+ ∙∙∙,"
|
1791
|
-
plain_line %( "b",)
|
1792
|
-
plain_line %( "c")
|
1793
|
-
plain_line " ]"
|
1794
|
-
plain_line " }"
|
1795
|
-
end
|
1796
|
-
}
|
1797
|
-
STR
|
1798
|
-
|
1799
|
-
expect(actual_output).to match_output(expected_output)
|
1800
|
-
end
|
1801
|
-
end
|
1802
|
-
|
1803
|
-
context "when a secondary layer of a data structure refers to itself" do
|
1804
|
-
it "replaces the reference with ∙∙∙" do
|
1805
|
-
expected = { foo: %w[a x b c] }
|
1806
|
-
actual = { foo: %w[a b c] }
|
1807
|
-
actual[:foo].insert(1, actual[:foo])
|
1808
|
-
|
1809
|
-
actual_output = described_class.call(expected: expected, actual: actual)
|
1810
|
-
|
1811
|
-
expected_output = <<~STR.strip
|
1812
|
-
Differing hashes.
|
1813
|
-
|
1814
|
-
#{
|
1815
|
-
colored do
|
1816
|
-
expected_line %(Expected: { foo: ["a", "x", "b", "c"] })
|
1817
|
-
actual_line %( Actual: { foo: ["a", ∙∙∙, "b", "c"] })
|
1818
|
-
end
|
1819
|
-
}
|
1820
|
-
|
1821
|
-
Diff:
|
1822
|
-
|
1823
|
-
#{
|
1824
|
-
colored do
|
1825
|
-
plain_line " {"
|
1826
|
-
plain_line " foo: ["
|
1827
|
-
plain_line %( "a",)
|
1828
|
-
expected_line %(- "x",)
|
1829
|
-
actual_line "+ ∙∙∙,"
|
1830
|
-
plain_line %( "b",)
|
1831
|
-
plain_line %( "c")
|
1832
|
-
plain_line " ]"
|
1833
|
-
plain_line " }"
|
1834
|
-
end
|
1835
|
-
}
|
1836
|
-
STR
|
1837
|
-
|
1838
|
-
expect(actual_output).to match_output(expected_output)
|
1839
|
-
end
|
1840
|
-
end
|
1841
|
-
end
|
1842
|
-
end
|