super_diff 0.13.0 → 0.14.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 +1 -1
- 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 +6 -4
- 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 +2 -0
- 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 +15 -9
- 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 +4 -2
- 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 +12 -10
- 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 +9 -6
- 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 +14 -38
- 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 +13 -11
- 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 -10
- 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 +2 -0
- 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/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 +15 -13
- data/lib/super_diff/version.rb +3 -1
- data/lib/super_diff.rb +24 -26
- data/super_diff.gemspec +20 -19
- metadata +6 -185
- data/spec/examples.txt +0 -450
- 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/spec_helper.rb +0 -91
- 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/point.rb +0 -7
- 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/inspection_tree_builders/data_object_spec.rb +0 -146
- data/spec/unit/basic/operation_tree_builders/data_object_spec.rb +0 -82
- 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/configuration_no_rspec_spec.rb +0 -58
- data/spec/unit/core/configuration_spec.rb +0 -176
- 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,1066 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe "Integration with RSpec's #eq matcher", type: :integration do
|
4
|
-
context "when comparing two different integers" do
|
5
|
-
it "produces the correct failure message when used in the positive" do
|
6
|
-
as_both_colored_and_uncolored do |color_enabled|
|
7
|
-
snippet = "expect(1).to eq(42)"
|
8
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
9
|
-
|
10
|
-
expected_output =
|
11
|
-
build_expected_output(
|
12
|
-
color_enabled: color_enabled,
|
13
|
-
snippet: snippet,
|
14
|
-
expectation:
|
15
|
-
proc do
|
16
|
-
line do
|
17
|
-
plain "Expected "
|
18
|
-
actual "1"
|
19
|
-
plain " to eq "
|
20
|
-
expected "42"
|
21
|
-
plain "."
|
22
|
-
end
|
23
|
-
end
|
24
|
-
)
|
25
|
-
|
26
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
27
|
-
color_enabled
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "produces the correct failure message when used in the negative" do
|
33
|
-
as_both_colored_and_uncolored do |color_enabled|
|
34
|
-
snippet = "expect(42).not_to eq(42)"
|
35
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
36
|
-
|
37
|
-
expected_output =
|
38
|
-
build_expected_output(
|
39
|
-
color_enabled: color_enabled,
|
40
|
-
snippet: snippet,
|
41
|
-
expectation:
|
42
|
-
proc do
|
43
|
-
line do
|
44
|
-
plain "Expected "
|
45
|
-
actual "42"
|
46
|
-
plain " not to eq "
|
47
|
-
expected "42"
|
48
|
-
plain "."
|
49
|
-
end
|
50
|
-
end
|
51
|
-
)
|
52
|
-
|
53
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
54
|
-
color_enabled
|
55
|
-
)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when comparing two different symbols" do
|
61
|
-
it "produces the correct failure message when used in the positive" do
|
62
|
-
as_both_colored_and_uncolored do |color_enabled|
|
63
|
-
snippet = "expect(:bar).to eq(:foo)"
|
64
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
65
|
-
|
66
|
-
expected_output =
|
67
|
-
build_expected_output(
|
68
|
-
color_enabled: color_enabled,
|
69
|
-
snippet: snippet,
|
70
|
-
expectation:
|
71
|
-
proc do
|
72
|
-
line do
|
73
|
-
plain "Expected "
|
74
|
-
actual ":bar"
|
75
|
-
plain " to eq "
|
76
|
-
expected ":foo"
|
77
|
-
plain "."
|
78
|
-
end
|
79
|
-
end
|
80
|
-
)
|
81
|
-
|
82
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
83
|
-
color_enabled
|
84
|
-
)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it "produces the correct failure message when used in the negative" do
|
89
|
-
as_both_colored_and_uncolored do |color_enabled|
|
90
|
-
snippet = "expect(:foo).not_to eq(:foo)"
|
91
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
92
|
-
|
93
|
-
expected_output =
|
94
|
-
build_expected_output(
|
95
|
-
color_enabled: color_enabled,
|
96
|
-
snippet: snippet,
|
97
|
-
expectation:
|
98
|
-
proc do
|
99
|
-
line do
|
100
|
-
plain "Expected "
|
101
|
-
actual ":foo"
|
102
|
-
plain " not to eq "
|
103
|
-
expected ":foo"
|
104
|
-
plain "."
|
105
|
-
end
|
106
|
-
end
|
107
|
-
)
|
108
|
-
|
109
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
110
|
-
color_enabled
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "when comparing two single-line strings" do
|
117
|
-
it "produces the correct failure message when used in the positive" do
|
118
|
-
as_both_colored_and_uncolored do |color_enabled|
|
119
|
-
snippet = %|expect("Jennifer").to eq("Marty")|
|
120
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
121
|
-
|
122
|
-
expected_output =
|
123
|
-
build_expected_output(
|
124
|
-
color_enabled: color_enabled,
|
125
|
-
snippet: %|expect("Jennifer").to eq("Marty")|,
|
126
|
-
expectation:
|
127
|
-
proc do
|
128
|
-
line do
|
129
|
-
plain "Expected "
|
130
|
-
actual %|"Jennifer"|
|
131
|
-
plain " to eq "
|
132
|
-
expected %|"Marty"|
|
133
|
-
plain "."
|
134
|
-
end
|
135
|
-
end
|
136
|
-
)
|
137
|
-
|
138
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
139
|
-
color_enabled
|
140
|
-
)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
it "produces the correct failure message when used in the negative" do
|
145
|
-
as_both_colored_and_uncolored do |color_enabled|
|
146
|
-
snippet = %|expect("Jennifer").not_to eq("Jennifer")|
|
147
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
148
|
-
|
149
|
-
expected_output =
|
150
|
-
build_expected_output(
|
151
|
-
color_enabled: color_enabled,
|
152
|
-
snippet: %|expect("Jennifer").not_to eq("Jennifer")|,
|
153
|
-
expectation:
|
154
|
-
proc do
|
155
|
-
line do
|
156
|
-
plain "Expected "
|
157
|
-
actual %|"Jennifer"|
|
158
|
-
plain " not to eq "
|
159
|
-
expected %|"Jennifer"|
|
160
|
-
plain "."
|
161
|
-
end
|
162
|
-
end
|
163
|
-
)
|
164
|
-
|
165
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
166
|
-
color_enabled
|
167
|
-
)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context "when comparing two different Time instances" do
|
173
|
-
it "produces the correct failure message when used in the positive" do
|
174
|
-
as_both_colored_and_uncolored do |color_enabled|
|
175
|
-
snippet = <<~RUBY
|
176
|
-
actual = Time.utc(2011, 12, 13, 14, 15, 16)
|
177
|
-
expected = Time.utc(2011, 12, 13, 14, 15, 16, 500_000)
|
178
|
-
expect(actual).to eq(expected)
|
179
|
-
RUBY
|
180
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
181
|
-
|
182
|
-
expected_output =
|
183
|
-
build_expected_output(
|
184
|
-
color_enabled: color_enabled,
|
185
|
-
snippet: "expect(actual).to eq(expected)",
|
186
|
-
expectation:
|
187
|
-
proc do
|
188
|
-
line do
|
189
|
-
plain "Expected "
|
190
|
-
actual "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
|
191
|
-
end
|
192
|
-
|
193
|
-
line do
|
194
|
-
plain " to eq "
|
195
|
-
expected "#<Time 2011-12-13 14:15:16+(1/2) +00:00 (UTC)>"
|
196
|
-
end
|
197
|
-
end,
|
198
|
-
diff:
|
199
|
-
proc do
|
200
|
-
plain_line " #<Time {"
|
201
|
-
plain_line " year: 2011,"
|
202
|
-
plain_line " month: 12,"
|
203
|
-
plain_line " day: 13,"
|
204
|
-
plain_line " hour: 14,"
|
205
|
-
plain_line " min: 15,"
|
206
|
-
plain_line " sec: 16,"
|
207
|
-
expected_line "- subsec: (1/2),"
|
208
|
-
actual_line "+ subsec: 0,"
|
209
|
-
plain_line " zone: \"UTC\","
|
210
|
-
plain_line " utc_offset: 0"
|
211
|
-
plain_line " }>"
|
212
|
-
end
|
213
|
-
)
|
214
|
-
|
215
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
216
|
-
color_enabled
|
217
|
-
)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
it "produces the correct failure message when used in the negative" do
|
222
|
-
as_both_colored_and_uncolored do |color_enabled|
|
223
|
-
snippet = <<~RUBY
|
224
|
-
time = Time.utc(2011, 12, 13, 14, 15, 16)
|
225
|
-
expect(time).not_to eq(time)
|
226
|
-
RUBY
|
227
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
228
|
-
|
229
|
-
expected_output =
|
230
|
-
build_expected_output(
|
231
|
-
color_enabled: color_enabled,
|
232
|
-
snippet: "expect(time).not_to eq(time)",
|
233
|
-
newline_before_expectation: true,
|
234
|
-
expectation:
|
235
|
-
proc do
|
236
|
-
line do
|
237
|
-
plain " Expected "
|
238
|
-
actual "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
|
239
|
-
end
|
240
|
-
|
241
|
-
line do
|
242
|
-
plain "not to eq "
|
243
|
-
expected "#<Time 2011-12-13 14:15:16 +00:00 (UTC)>"
|
244
|
-
end
|
245
|
-
end
|
246
|
-
)
|
247
|
-
|
248
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
249
|
-
color_enabled
|
250
|
-
)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
context "when comparing two different Date instances" do
|
256
|
-
it "produces the correct failure message when used in the positive" do
|
257
|
-
as_both_colored_and_uncolored do |color_enabled|
|
258
|
-
snippet = <<~RUBY
|
259
|
-
actual = Date.new(2023, 10, 14)
|
260
|
-
expected = Date.new(2023, 10, 31)
|
261
|
-
expect(actual).to eq(expected)
|
262
|
-
RUBY
|
263
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
264
|
-
|
265
|
-
expected_output =
|
266
|
-
build_expected_output(
|
267
|
-
color_enabled: color_enabled,
|
268
|
-
snippet: "expect(actual).to eq(expected)",
|
269
|
-
expectation:
|
270
|
-
proc do
|
271
|
-
line do
|
272
|
-
plain "Expected "
|
273
|
-
actual "#<Date 2023-10-14>"
|
274
|
-
plain " to eq "
|
275
|
-
expected "#<Date 2023-10-31>"
|
276
|
-
plain "."
|
277
|
-
end
|
278
|
-
end,
|
279
|
-
diff:
|
280
|
-
proc do
|
281
|
-
plain_line " #<Date {"
|
282
|
-
plain_line " year: 2023,"
|
283
|
-
plain_line " month: 10,"
|
284
|
-
expected_line "- day: 31"
|
285
|
-
actual_line "+ day: 14"
|
286
|
-
plain_line " }>"
|
287
|
-
end
|
288
|
-
)
|
289
|
-
|
290
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
291
|
-
color_enabled
|
292
|
-
)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
it "produces the correct failure message when used in the negative" do
|
297
|
-
as_both_colored_and_uncolored do |color_enabled|
|
298
|
-
snippet = <<~RUBY
|
299
|
-
date = Date.new(2023, 10, 14)
|
300
|
-
expect(date).not_to eq(date)
|
301
|
-
RUBY
|
302
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
303
|
-
|
304
|
-
expected_output =
|
305
|
-
build_expected_output(
|
306
|
-
color_enabled: color_enabled,
|
307
|
-
snippet: "expect(date).not_to eq(date)",
|
308
|
-
expectation:
|
309
|
-
proc do
|
310
|
-
line do
|
311
|
-
plain "Expected "
|
312
|
-
actual "#<Date 2023-10-14>"
|
313
|
-
plain " not to eq "
|
314
|
-
expected "#<Date 2023-10-14>"
|
315
|
-
plain "."
|
316
|
-
end
|
317
|
-
end
|
318
|
-
)
|
319
|
-
|
320
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
321
|
-
color_enabled
|
322
|
-
)
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
context "when comparing a single-line string with a multi-line string" do
|
328
|
-
it "produces the correct failure message" do
|
329
|
-
as_both_colored_and_uncolored do |color_enabled|
|
330
|
-
snippet = <<~TEST.strip
|
331
|
-
actual = "This is a line\\nAnd that's another line\\n"
|
332
|
-
expected = "Something entirely different"
|
333
|
-
expect(actual).to eq(expected)
|
334
|
-
TEST
|
335
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
336
|
-
|
337
|
-
expected_output =
|
338
|
-
build_expected_output(
|
339
|
-
color_enabled: color_enabled,
|
340
|
-
snippet: "expect(actual).to eq(expected)",
|
341
|
-
expectation:
|
342
|
-
proc do
|
343
|
-
line do
|
344
|
-
plain "Expected "
|
345
|
-
actual %|"This is a line\\nAnd that's another line\\n"|
|
346
|
-
plain " to eq "
|
347
|
-
expected %|"Something entirely different"|
|
348
|
-
plain "."
|
349
|
-
end
|
350
|
-
end,
|
351
|
-
diff:
|
352
|
-
proc do
|
353
|
-
expected_line "- Something entirely different"
|
354
|
-
actual_line %|+ This is a line\\n|
|
355
|
-
actual_line %|+ And that's another line\\n|
|
356
|
-
end
|
357
|
-
)
|
358
|
-
|
359
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
360
|
-
color_enabled
|
361
|
-
)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
context "when comparing a multi-line string with a single-line string" do
|
367
|
-
it "produces the correct failure message" do
|
368
|
-
as_both_colored_and_uncolored do |color_enabled|
|
369
|
-
snippet = <<~TEST.strip
|
370
|
-
actual = "Something entirely different"
|
371
|
-
expected = "This is a line\\nAnd that's another line\\n"
|
372
|
-
expect(actual).to eq(expected)
|
373
|
-
TEST
|
374
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
375
|
-
|
376
|
-
expected_output =
|
377
|
-
build_expected_output(
|
378
|
-
color_enabled: color_enabled,
|
379
|
-
snippet: "expect(actual).to eq(expected)",
|
380
|
-
expectation:
|
381
|
-
proc do
|
382
|
-
line do
|
383
|
-
plain "Expected "
|
384
|
-
actual %|"Something entirely different"|
|
385
|
-
plain " to eq "
|
386
|
-
expected %|"This is a line\\nAnd that's another line\\n"|
|
387
|
-
plain "."
|
388
|
-
end
|
389
|
-
end,
|
390
|
-
diff:
|
391
|
-
proc do
|
392
|
-
expected_line %|- This is a line\\n|
|
393
|
-
expected_line %|- And that's another line\\n|
|
394
|
-
actual_line "+ Something entirely different"
|
395
|
-
end
|
396
|
-
)
|
397
|
-
|
398
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
399
|
-
color_enabled
|
400
|
-
)
|
401
|
-
end
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
context "when comparing two multi-line strings" do
|
406
|
-
it "produces the correct failure message when used in the positive" do
|
407
|
-
as_both_colored_and_uncolored do |color_enabled|
|
408
|
-
snippet = <<~TEST.strip
|
409
|
-
actual = "This is a line\\nSomething completely different\\nAnd there's a line too\\n"
|
410
|
-
expected = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
|
411
|
-
expect(actual).to eq(expected)
|
412
|
-
TEST
|
413
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
414
|
-
|
415
|
-
expected_output =
|
416
|
-
build_expected_output(
|
417
|
-
color_enabled: color_enabled,
|
418
|
-
snippet: "expect(actual).to eq(expected)",
|
419
|
-
expectation:
|
420
|
-
proc do
|
421
|
-
line do
|
422
|
-
plain "Expected "
|
423
|
-
actual %|"This is a line\\nSomething completely different\\nAnd there's a line too\\n"|
|
424
|
-
end
|
425
|
-
|
426
|
-
line do
|
427
|
-
plain " to eq "
|
428
|
-
expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
|
429
|
-
end
|
430
|
-
end,
|
431
|
-
diff:
|
432
|
-
proc do
|
433
|
-
plain_line %| This is a line\\n|
|
434
|
-
expected_line %|- And that's a line\\n|
|
435
|
-
actual_line %|+ Something completely different\\n|
|
436
|
-
plain_line %| And there's a line too\\n|
|
437
|
-
end
|
438
|
-
)
|
439
|
-
|
440
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
441
|
-
color_enabled
|
442
|
-
)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
it "produces the correct failure message when used in the negative" do
|
447
|
-
as_both_colored_and_uncolored do |color_enabled|
|
448
|
-
snippet = <<~TEST.strip
|
449
|
-
string = "This is a line\\nAnd that's a line\\nAnd there's a line too\\n"
|
450
|
-
expect(string).not_to eq(string)
|
451
|
-
TEST
|
452
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
453
|
-
|
454
|
-
expected_output =
|
455
|
-
build_expected_output(
|
456
|
-
color_enabled: color_enabled,
|
457
|
-
snippet: "expect(string).not_to eq(string)",
|
458
|
-
newline_before_expectation: true,
|
459
|
-
expectation:
|
460
|
-
proc do
|
461
|
-
line do
|
462
|
-
plain " Expected "
|
463
|
-
actual %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
|
464
|
-
end
|
465
|
-
|
466
|
-
line do
|
467
|
-
plain "not to eq "
|
468
|
-
expected %|"This is a line\\nAnd that's a line\\nAnd there's a line too\\n"|
|
469
|
-
end
|
470
|
-
end
|
471
|
-
)
|
472
|
-
|
473
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
474
|
-
color_enabled
|
475
|
-
)
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
479
|
-
|
480
|
-
context "when comparing two arrays with other data structures inside" do
|
481
|
-
it "produces the correct failure message when used in the positive" do
|
482
|
-
as_both_colored_and_uncolored do |color_enabled|
|
483
|
-
snippet = <<~TEST
|
484
|
-
actual = [
|
485
|
-
[
|
486
|
-
:h2,
|
487
|
-
[:span, [:text, "Goodbye world"]],
|
488
|
-
{
|
489
|
-
id: "hero",
|
490
|
-
class: "header",
|
491
|
-
data: {
|
492
|
-
"sticky" => false,
|
493
|
-
role: "deprecated",
|
494
|
-
person: SuperDiff::Test::Person.new(name: "Doc", age: 60)
|
495
|
-
}
|
496
|
-
}
|
497
|
-
],
|
498
|
-
:br
|
499
|
-
]
|
500
|
-
expected = [
|
501
|
-
[
|
502
|
-
:h1,
|
503
|
-
[:span, [:text, "Hello world"]],
|
504
|
-
{
|
505
|
-
class: "header",
|
506
|
-
data: {
|
507
|
-
"sticky" => true,
|
508
|
-
person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
|
509
|
-
}
|
510
|
-
}
|
511
|
-
]
|
512
|
-
]
|
513
|
-
expect(actual).to eq(expected)
|
514
|
-
TEST
|
515
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
516
|
-
|
517
|
-
expected_output =
|
518
|
-
build_expected_output(
|
519
|
-
color_enabled: color_enabled,
|
520
|
-
snippet: "expect(actual).to eq(expected)",
|
521
|
-
expectation:
|
522
|
-
proc do
|
523
|
-
line do
|
524
|
-
plain "Expected "
|
525
|
-
actual %|[[:h2, [:span, [:text, "Goodbye world"]], { id: "hero", class: "header", data: { "sticky" => false, :role => "deprecated", :person => #<SuperDiff::Test::Person name: "Doc", age: 60> } }], :br]|
|
526
|
-
end
|
527
|
-
|
528
|
-
line do
|
529
|
-
plain " to eq "
|
530
|
-
expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
|
531
|
-
end
|
532
|
-
end,
|
533
|
-
diff:
|
534
|
-
proc do
|
535
|
-
plain_line " ["
|
536
|
-
plain_line " ["
|
537
|
-
expected_line "- :h1,"
|
538
|
-
actual_line "+ :h2,"
|
539
|
-
plain_line " ["
|
540
|
-
plain_line " :span,"
|
541
|
-
plain_line " ["
|
542
|
-
plain_line " :text,"
|
543
|
-
expected_line %|- "Hello world"|
|
544
|
-
actual_line %|+ "Goodbye world"|
|
545
|
-
plain_line " ]"
|
546
|
-
plain_line " ],"
|
547
|
-
plain_line " {"
|
548
|
-
actual_line %|+ id: "hero",|
|
549
|
-
plain_line %| class: "header",|
|
550
|
-
plain_line " data: {"
|
551
|
-
expected_line %|- "sticky" => true,|
|
552
|
-
actual_line %|+ "sticky" => false,|
|
553
|
-
actual_line %|+ :role => "deprecated",|
|
554
|
-
plain_line " :person => #<SuperDiff::Test::Person {"
|
555
|
-
expected_line %|- name: "Marty",|
|
556
|
-
actual_line %|+ name: "Doc",|
|
557
|
-
plain_line " age: 60"
|
558
|
-
plain_line " }>"
|
559
|
-
plain_line " }"
|
560
|
-
plain_line " }"
|
561
|
-
plain_line " ],"
|
562
|
-
actual_line "+ :br"
|
563
|
-
plain_line " ]"
|
564
|
-
end
|
565
|
-
)
|
566
|
-
|
567
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
568
|
-
color_enabled
|
569
|
-
)
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
it "produces the correct failure message when used in the negative" do
|
574
|
-
as_both_colored_and_uncolored do |color_enabled|
|
575
|
-
snippet = <<~TEST
|
576
|
-
value = [
|
577
|
-
[
|
578
|
-
:h1,
|
579
|
-
[:span, [:text, "Hello world"]],
|
580
|
-
{
|
581
|
-
class: "header",
|
582
|
-
data: {
|
583
|
-
"sticky" => true,
|
584
|
-
person: SuperDiff::Test::Person.new(name: "Marty", age: 60)
|
585
|
-
}
|
586
|
-
}
|
587
|
-
]
|
588
|
-
]
|
589
|
-
expect(value).not_to eq(value)
|
590
|
-
TEST
|
591
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
592
|
-
|
593
|
-
expected_output =
|
594
|
-
build_expected_output(
|
595
|
-
color_enabled: color_enabled,
|
596
|
-
snippet: "expect(value).not_to eq(value)",
|
597
|
-
newline_before_expectation: true,
|
598
|
-
expectation:
|
599
|
-
proc do
|
600
|
-
line do
|
601
|
-
plain " Expected "
|
602
|
-
actual %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
|
603
|
-
end
|
604
|
-
|
605
|
-
line do
|
606
|
-
plain "not to eq "
|
607
|
-
expected %|[[:h1, [:span, [:text, "Hello world"]], { class: "header", data: { "sticky" => true, :person => #<SuperDiff::Test::Person name: "Marty", age: 60> } }]]|
|
608
|
-
end
|
609
|
-
end
|
610
|
-
)
|
611
|
-
|
612
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
613
|
-
color_enabled
|
614
|
-
)
|
615
|
-
end
|
616
|
-
end
|
617
|
-
end
|
618
|
-
|
619
|
-
context "when comparing two hashes with other data structures inside" do
|
620
|
-
it "produces the correct failure message when used in the positive" do
|
621
|
-
as_both_colored_and_uncolored do |color_enabled|
|
622
|
-
snippet = <<~TEST.strip
|
623
|
-
actual = {
|
624
|
-
customer: {
|
625
|
-
person: SuperDiff::Test::Person.new(name: "Marty McFly, Jr.", age: 17),
|
626
|
-
shipping_address: {
|
627
|
-
line_1: "456 Ponderosa Ct.",
|
628
|
-
city: "Hill Valley",
|
629
|
-
state: "CA",
|
630
|
-
zip: "90382"
|
631
|
-
}
|
632
|
-
},
|
633
|
-
items: [
|
634
|
-
{
|
635
|
-
name: "Fender Stratocaster",
|
636
|
-
cost: 100_000,
|
637
|
-
options: ["red", "blue", "green"]
|
638
|
-
},
|
639
|
-
{ name: "Mattel Hoverboard" }
|
640
|
-
]
|
641
|
-
}
|
642
|
-
expected = {
|
643
|
-
customer: {
|
644
|
-
person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
|
645
|
-
shipping_address: {
|
646
|
-
line_1: "123 Main St.",
|
647
|
-
city: "Hill Valley",
|
648
|
-
state: "CA",
|
649
|
-
zip: "90382"
|
650
|
-
}
|
651
|
-
},
|
652
|
-
items: [
|
653
|
-
{
|
654
|
-
name: "Fender Stratocaster",
|
655
|
-
cost: 100_000,
|
656
|
-
options: ["red", "blue", "green"]
|
657
|
-
},
|
658
|
-
{ name: "Chevy 4x4" }
|
659
|
-
]
|
660
|
-
}
|
661
|
-
expect(actual).to eq(expected)
|
662
|
-
TEST
|
663
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
664
|
-
|
665
|
-
expected_output =
|
666
|
-
build_expected_output(
|
667
|
-
color_enabled: color_enabled,
|
668
|
-
snippet: "expect(actual).to eq(expected)",
|
669
|
-
expectation:
|
670
|
-
proc do
|
671
|
-
line do
|
672
|
-
plain "Expected "
|
673
|
-
actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly, Jr.", age: 17>, 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" }] }|
|
674
|
-
end
|
675
|
-
|
676
|
-
line do
|
677
|
-
plain " to eq "
|
678
|
-
expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, 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" }] }|
|
679
|
-
end
|
680
|
-
end,
|
681
|
-
diff:
|
682
|
-
proc do
|
683
|
-
plain_line " {"
|
684
|
-
plain_line " customer: {"
|
685
|
-
plain_line " person: #<SuperDiff::Test::Person {"
|
686
|
-
expected_line %|- name: "Marty McFly",|
|
687
|
-
actual_line %|+ name: "Marty McFly, Jr.",|
|
688
|
-
plain_line " age: 17"
|
689
|
-
plain_line " }>,"
|
690
|
-
plain_line " shipping_address: {"
|
691
|
-
expected_line %|- line_1: "123 Main St.",|
|
692
|
-
actual_line %|+ line_1: "456 Ponderosa Ct.",|
|
693
|
-
plain_line %| city: "Hill Valley",|
|
694
|
-
plain_line %| state: "CA",|
|
695
|
-
plain_line %| zip: "90382"|
|
696
|
-
plain_line " }"
|
697
|
-
plain_line " },"
|
698
|
-
plain_line " items: ["
|
699
|
-
plain_line " {"
|
700
|
-
plain_line %| name: "Fender Stratocaster",|
|
701
|
-
plain_line " cost: 100000,"
|
702
|
-
plain_line " options: ["
|
703
|
-
plain_line %| "red",|
|
704
|
-
plain_line %| "blue",|
|
705
|
-
plain_line %| "green"|
|
706
|
-
plain_line " ]"
|
707
|
-
plain_line " },"
|
708
|
-
plain_line " {"
|
709
|
-
expected_line %|- name: "Chevy 4x4"|
|
710
|
-
actual_line %|+ name: "Mattel Hoverboard"|
|
711
|
-
plain_line " }"
|
712
|
-
plain_line " ]"
|
713
|
-
plain_line " }"
|
714
|
-
end
|
715
|
-
)
|
716
|
-
|
717
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
718
|
-
color_enabled
|
719
|
-
)
|
720
|
-
end
|
721
|
-
end
|
722
|
-
|
723
|
-
it "produces the correct failure message when used in the negative" do
|
724
|
-
as_both_colored_and_uncolored do |color_enabled|
|
725
|
-
snippet = <<~TEST.strip
|
726
|
-
value = {
|
727
|
-
customer: {
|
728
|
-
person: SuperDiff::Test::Person.new(name: "Marty McFly", age: 17),
|
729
|
-
shipping_address: {
|
730
|
-
line_1: "123 Main St.",
|
731
|
-
city: "Hill Valley",
|
732
|
-
state: "CA",
|
733
|
-
zip: "90382"
|
734
|
-
}
|
735
|
-
},
|
736
|
-
items: [
|
737
|
-
{
|
738
|
-
name: "Fender Stratocaster",
|
739
|
-
cost: 100_000,
|
740
|
-
options: ["red", "blue", "green"]
|
741
|
-
},
|
742
|
-
{ name: "Chevy 4x4" }
|
743
|
-
]
|
744
|
-
}
|
745
|
-
expect(value).not_to eq(value)
|
746
|
-
TEST
|
747
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
748
|
-
|
749
|
-
expected_output =
|
750
|
-
build_expected_output(
|
751
|
-
color_enabled: color_enabled,
|
752
|
-
snippet: "expect(value).not_to eq(value)",
|
753
|
-
newline_before_expectation: true,
|
754
|
-
expectation:
|
755
|
-
proc do
|
756
|
-
line do
|
757
|
-
plain " Expected "
|
758
|
-
actual %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, 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" }] }|
|
759
|
-
end
|
760
|
-
|
761
|
-
line do
|
762
|
-
plain "not to eq "
|
763
|
-
expected %|{ customer: { person: #<SuperDiff::Test::Person name: "Marty McFly", age: 17>, 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" }] }|
|
764
|
-
end
|
765
|
-
end
|
766
|
-
)
|
767
|
-
|
768
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
769
|
-
color_enabled
|
770
|
-
)
|
771
|
-
end
|
772
|
-
end
|
773
|
-
end
|
774
|
-
|
775
|
-
context "when comparing two different kinds of custom objects" do
|
776
|
-
it "produces the correct failure message when used in the positive" do
|
777
|
-
as_both_colored_and_uncolored do |color_enabled|
|
778
|
-
snippet = <<~TEST.strip
|
779
|
-
actual = SuperDiff::Test::Customer.new(
|
780
|
-
name: "Doc",
|
781
|
-
shipping_address: :some_shipping_address,
|
782
|
-
phone: "1234567890",
|
783
|
-
)
|
784
|
-
expected = SuperDiff::Test::Person.new(
|
785
|
-
name: "Marty",
|
786
|
-
age: 31,
|
787
|
-
)
|
788
|
-
expect(actual).to eq(expected)
|
789
|
-
TEST
|
790
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
791
|
-
|
792
|
-
expected_output =
|
793
|
-
build_expected_output(
|
794
|
-
color_enabled: color_enabled,
|
795
|
-
snippet: "expect(actual).to eq(expected)",
|
796
|
-
newline_before_expectation: true,
|
797
|
-
expectation:
|
798
|
-
proc do
|
799
|
-
line do
|
800
|
-
plain "Expected "
|
801
|
-
actual %|#<SuperDiff::Test::Customer name: "Doc", shipping_address: :some_shipping_address, phone: "1234567890">|
|
802
|
-
end
|
803
|
-
|
804
|
-
line do
|
805
|
-
plain " to eq "
|
806
|
-
expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
|
807
|
-
end
|
808
|
-
end
|
809
|
-
)
|
810
|
-
|
811
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
812
|
-
color_enabled
|
813
|
-
)
|
814
|
-
end
|
815
|
-
end
|
816
|
-
|
817
|
-
it "produces the correct failure message when used in the negative" do
|
818
|
-
as_both_colored_and_uncolored do |color_enabled|
|
819
|
-
snippet = <<~TEST.strip
|
820
|
-
value = SuperDiff::Test::Person.new(
|
821
|
-
name: "Marty",
|
822
|
-
age: 31,
|
823
|
-
)
|
824
|
-
expect(value).not_to eq(value)
|
825
|
-
TEST
|
826
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
827
|
-
|
828
|
-
expected_output =
|
829
|
-
build_expected_output(
|
830
|
-
color_enabled: color_enabled,
|
831
|
-
snippet: "expect(value).not_to eq(value)",
|
832
|
-
newline_before_expectation: true,
|
833
|
-
expectation:
|
834
|
-
proc do
|
835
|
-
line do
|
836
|
-
plain " Expected "
|
837
|
-
actual %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
|
838
|
-
end
|
839
|
-
|
840
|
-
line do
|
841
|
-
plain "not to eq "
|
842
|
-
expected %|#<SuperDiff::Test::Person name: "Marty", age: 31>|
|
843
|
-
end
|
844
|
-
end
|
845
|
-
)
|
846
|
-
|
847
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
848
|
-
color_enabled
|
849
|
-
)
|
850
|
-
end
|
851
|
-
end
|
852
|
-
end
|
853
|
-
|
854
|
-
context "when comparing two different kinds of non-custom objects" do
|
855
|
-
it "produces the correct failure message when used in the positive" do
|
856
|
-
as_both_colored_and_uncolored do |color_enabled|
|
857
|
-
snippet = <<~TEST.strip
|
858
|
-
actual = SuperDiff::Test::Player.new(
|
859
|
-
handle: "mcmire",
|
860
|
-
character: "Jon",
|
861
|
-
inventory: ["sword"],
|
862
|
-
shields: 11.4,
|
863
|
-
health: 4,
|
864
|
-
ultimate: true,
|
865
|
-
)
|
866
|
-
expected = SuperDiff::Test::Item.new(
|
867
|
-
name: "camera",
|
868
|
-
quantity: 3,
|
869
|
-
)
|
870
|
-
expect(actual).to eq(expected)
|
871
|
-
TEST
|
872
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
873
|
-
|
874
|
-
expected_output =
|
875
|
-
build_expected_output(
|
876
|
-
color_enabled: color_enabled,
|
877
|
-
snippet: "expect(actual).to eq(expected)",
|
878
|
-
newline_before_expectation: true,
|
879
|
-
expectation:
|
880
|
-
proc do
|
881
|
-
line do
|
882
|
-
plain "Expected "
|
883
|
-
actual %|#<SuperDiff::Test::Player @character="Jon", @handle="mcmire", @health=4, @inventory=["sword"], @shields=11.4, @ultimate=true>|
|
884
|
-
end
|
885
|
-
|
886
|
-
line do
|
887
|
-
plain " to eq "
|
888
|
-
expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
|
889
|
-
end
|
890
|
-
end
|
891
|
-
)
|
892
|
-
|
893
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
894
|
-
color_enabled
|
895
|
-
).removing_object_ids
|
896
|
-
end
|
897
|
-
end
|
898
|
-
|
899
|
-
it "produces the correct failure message when used in the negative" do
|
900
|
-
as_both_colored_and_uncolored do |color_enabled|
|
901
|
-
snippet = <<~TEST.strip
|
902
|
-
value = SuperDiff::Test::Item.new(
|
903
|
-
name: "camera",
|
904
|
-
quantity: 3,
|
905
|
-
)
|
906
|
-
expect(value).not_to eq(value)
|
907
|
-
TEST
|
908
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
909
|
-
|
910
|
-
expected_output =
|
911
|
-
build_expected_output(
|
912
|
-
color_enabled: color_enabled,
|
913
|
-
snippet: "expect(value).not_to eq(value)",
|
914
|
-
newline_before_expectation: true,
|
915
|
-
expectation:
|
916
|
-
proc do
|
917
|
-
line do
|
918
|
-
plain " Expected "
|
919
|
-
actual %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
|
920
|
-
end
|
921
|
-
|
922
|
-
line do
|
923
|
-
plain "not to eq "
|
924
|
-
expected %|#<SuperDiff::Test::Item @name="camera", @quantity=3>|
|
925
|
-
end
|
926
|
-
end
|
927
|
-
)
|
928
|
-
|
929
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
930
|
-
color_enabled
|
931
|
-
).removing_object_ids
|
932
|
-
end
|
933
|
-
end
|
934
|
-
end
|
935
|
-
|
936
|
-
context "when comparing two data structures where one contains an empty array" do
|
937
|
-
it "formats the array correctly in the diff" do
|
938
|
-
as_both_colored_and_uncolored do |color_enabled|
|
939
|
-
snippet = <<~TEST.strip
|
940
|
-
actual = { foo: [] }
|
941
|
-
expected = { foo: nil }
|
942
|
-
expect(actual).to eq(expected)
|
943
|
-
TEST
|
944
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
945
|
-
|
946
|
-
expected_output =
|
947
|
-
build_expected_output(
|
948
|
-
color_enabled: color_enabled,
|
949
|
-
snippet: "expect(actual).to eq(expected)",
|
950
|
-
newline_before_expectation: true,
|
951
|
-
expectation:
|
952
|
-
proc do
|
953
|
-
line do
|
954
|
-
plain "Expected "
|
955
|
-
actual "{ foo: [] }"
|
956
|
-
plain " to eq "
|
957
|
-
expected "{ foo: nil }"
|
958
|
-
plain "."
|
959
|
-
end
|
960
|
-
end,
|
961
|
-
diff:
|
962
|
-
proc do
|
963
|
-
plain_line " {"
|
964
|
-
expected_line "- foo: nil"
|
965
|
-
actual_line "+ foo: []"
|
966
|
-
plain_line " }"
|
967
|
-
end
|
968
|
-
)
|
969
|
-
|
970
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
971
|
-
color_enabled
|
972
|
-
)
|
973
|
-
end
|
974
|
-
end
|
975
|
-
end
|
976
|
-
|
977
|
-
context "when comparing two data structures where one contains an empty hash" do
|
978
|
-
it "formats the hash correctly in the diff" do
|
979
|
-
as_both_colored_and_uncolored do |color_enabled|
|
980
|
-
snippet = <<~TEST.strip
|
981
|
-
actual = { foo: {} }
|
982
|
-
expected = { foo: nil }
|
983
|
-
expect(actual).to eq(expected)
|
984
|
-
TEST
|
985
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
986
|
-
|
987
|
-
expected_output =
|
988
|
-
build_expected_output(
|
989
|
-
color_enabled: color_enabled,
|
990
|
-
snippet: "expect(actual).to eq(expected)",
|
991
|
-
newline_before_expectation: true,
|
992
|
-
expectation:
|
993
|
-
proc do
|
994
|
-
line do
|
995
|
-
plain "Expected "
|
996
|
-
actual "{ foo: {} }"
|
997
|
-
plain " to eq "
|
998
|
-
expected "{ foo: nil }"
|
999
|
-
plain "."
|
1000
|
-
end
|
1001
|
-
end,
|
1002
|
-
diff:
|
1003
|
-
proc do
|
1004
|
-
plain_line " {"
|
1005
|
-
expected_line "- foo: nil"
|
1006
|
-
actual_line "+ foo: {}"
|
1007
|
-
plain_line " }"
|
1008
|
-
end
|
1009
|
-
)
|
1010
|
-
|
1011
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
1012
|
-
color_enabled
|
1013
|
-
)
|
1014
|
-
end
|
1015
|
-
end
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
context "when comparing two data structures where one contains an empty object" do
|
1019
|
-
it "formats the object correctly in the diff" do
|
1020
|
-
as_both_colored_and_uncolored do |color_enabled|
|
1021
|
-
snippet = <<~TEST.strip
|
1022
|
-
actual = { foo: SuperDiff::Test::EmptyClass.new }
|
1023
|
-
expected = { foo: nil }
|
1024
|
-
expect(actual).to eq(expected)
|
1025
|
-
TEST
|
1026
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
1027
|
-
|
1028
|
-
expected_output =
|
1029
|
-
build_expected_output(
|
1030
|
-
color_enabled: color_enabled,
|
1031
|
-
snippet: "expect(actual).to eq(expected)",
|
1032
|
-
newline_before_expectation: true,
|
1033
|
-
expectation:
|
1034
|
-
proc do
|
1035
|
-
line do
|
1036
|
-
plain "Expected "
|
1037
|
-
actual "{ foo: #<SuperDiff::Test::EmptyClass> }"
|
1038
|
-
plain " to eq "
|
1039
|
-
expected "{ foo: nil }"
|
1040
|
-
plain "."
|
1041
|
-
end
|
1042
|
-
end,
|
1043
|
-
diff:
|
1044
|
-
proc do
|
1045
|
-
plain_line " {"
|
1046
|
-
expected_line "- foo: nil"
|
1047
|
-
actual_line "+ foo: #<SuperDiff::Test::EmptyClass>"
|
1048
|
-
plain_line " }"
|
1049
|
-
end
|
1050
|
-
)
|
1051
|
-
|
1052
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
1053
|
-
color_enabled
|
1054
|
-
).removing_object_ids
|
1055
|
-
end
|
1056
|
-
end
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
it_behaves_like "a matcher that supports elided diffs" do
|
1060
|
-
let(:matcher) { :eq }
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
it_behaves_like "a matcher that supports a toggleable key" do
|
1064
|
-
let(:matcher) { :eq }
|
1065
|
-
end
|
1066
|
-
end
|