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,177 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe "Integration with describable matchers not handled specially",
|
4
|
-
type: :integration do
|
5
|
-
context "when the expected value contains a built-in matcher (not an aliased matcher)" do
|
6
|
-
it "produces the correct failure message when used in the positive" do
|
7
|
-
as_both_colored_and_uncolored do |color_enabled|
|
8
|
-
snippet = <<~TEST.strip
|
9
|
-
actual = {
|
10
|
-
number: "not a number"
|
11
|
-
}
|
12
|
-
expected = hash_including(
|
13
|
-
number: be_a(Numeric)
|
14
|
-
)
|
15
|
-
expect(actual).to match(expected)
|
16
|
-
TEST
|
17
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
18
|
-
|
19
|
-
expected_output =
|
20
|
-
build_expected_output(
|
21
|
-
color_enabled: color_enabled,
|
22
|
-
snippet: "expect(actual).to match(expected)",
|
23
|
-
expectation:
|
24
|
-
proc do
|
25
|
-
line do
|
26
|
-
plain "Expected "
|
27
|
-
actual %|{ number: "not a number" }|
|
28
|
-
plain " to match "
|
29
|
-
expected "#<a hash including (number: #<be a kind of Numeric>)>"
|
30
|
-
plain "."
|
31
|
-
end
|
32
|
-
end,
|
33
|
-
diff:
|
34
|
-
proc do
|
35
|
-
plain_line " {"
|
36
|
-
expected_line "- number: #<be a kind of Numeric>"
|
37
|
-
actual_line %|+ number: "not a number"|
|
38
|
-
plain_line " }"
|
39
|
-
end
|
40
|
-
)
|
41
|
-
|
42
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
43
|
-
color_enabled
|
44
|
-
)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "produces the correct failure message when used in the negative" do
|
49
|
-
as_both_colored_and_uncolored do |color_enabled|
|
50
|
-
snippet = <<~TEST.strip
|
51
|
-
actual = {
|
52
|
-
number: 4
|
53
|
-
}
|
54
|
-
expected = hash_including(
|
55
|
-
number: be_a(Numeric)
|
56
|
-
)
|
57
|
-
expect(actual).not_to match(expected)
|
58
|
-
TEST
|
59
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
60
|
-
|
61
|
-
expected_output =
|
62
|
-
build_expected_output(
|
63
|
-
color_enabled: color_enabled,
|
64
|
-
snippet: "expect(actual).not_to match(expected)",
|
65
|
-
expectation:
|
66
|
-
proc do
|
67
|
-
line do
|
68
|
-
plain "Expected "
|
69
|
-
actual "{ number: 4 }"
|
70
|
-
plain " not to match "
|
71
|
-
expected "#<a hash including (number: #<be a kind of Numeric>)>"
|
72
|
-
plain "."
|
73
|
-
end
|
74
|
-
end
|
75
|
-
)
|
76
|
-
|
77
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
78
|
-
color_enabled
|
79
|
-
)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when the expected value contains a custom matcher defined via RSpec::Matchers::DSL" do
|
85
|
-
it "produces the correct failure message" do
|
86
|
-
as_both_colored_and_uncolored do |color_enabled|
|
87
|
-
snippet = <<~TEST.strip
|
88
|
-
actual = {
|
89
|
-
number: "something else"
|
90
|
-
}
|
91
|
-
expected = hash_including(
|
92
|
-
number: failing_custom_matcher_from_dsl(42)
|
93
|
-
)
|
94
|
-
expect(actual).to match(expected)
|
95
|
-
TEST
|
96
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
97
|
-
|
98
|
-
expected_output =
|
99
|
-
build_expected_output(
|
100
|
-
color_enabled: color_enabled,
|
101
|
-
snippet: "expect(actual).to match(expected)",
|
102
|
-
newline_before_expectation: true,
|
103
|
-
expectation:
|
104
|
-
proc do
|
105
|
-
line do
|
106
|
-
plain "Expected "
|
107
|
-
actual %|{ number: "something else" }|
|
108
|
-
end
|
109
|
-
|
110
|
-
line do
|
111
|
-
plain "to match "
|
112
|
-
expected "#<a hash including (number: #<custom matcher defined via the DSL with value 42>)>"
|
113
|
-
end
|
114
|
-
end,
|
115
|
-
diff:
|
116
|
-
proc do
|
117
|
-
plain_line " {"
|
118
|
-
expected_line "- number: #<custom matcher defined via the DSL with value 42>"
|
119
|
-
actual_line %|+ number: "something else"|
|
120
|
-
plain_line " }"
|
121
|
-
end
|
122
|
-
)
|
123
|
-
|
124
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
125
|
-
color_enabled
|
126
|
-
)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context "when the expected value contains a custom matcher defined from scratch" do
|
132
|
-
it "produces the correct failure message" do
|
133
|
-
as_both_colored_and_uncolored do |color_enabled|
|
134
|
-
snippet = <<~TEST.strip
|
135
|
-
actual = {
|
136
|
-
number: "something else"
|
137
|
-
}
|
138
|
-
expected = hash_including(
|
139
|
-
number: failing_custom_matcher_from_scratch(42)
|
140
|
-
)
|
141
|
-
expect(actual).to match(expected)
|
142
|
-
TEST
|
143
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
144
|
-
|
145
|
-
expected_output =
|
146
|
-
build_expected_output(
|
147
|
-
color_enabled: color_enabled,
|
148
|
-
snippet: "expect(actual).to match(expected)",
|
149
|
-
newline_before_expectation: true,
|
150
|
-
expectation:
|
151
|
-
proc do
|
152
|
-
line do
|
153
|
-
plain "Expected "
|
154
|
-
actual %|{ number: "something else" }|
|
155
|
-
end
|
156
|
-
|
157
|
-
line do
|
158
|
-
plain "to match "
|
159
|
-
expected "#<a hash including (number: #<custom matcher defined from scratch with value 42>)>"
|
160
|
-
end
|
161
|
-
end,
|
162
|
-
diff:
|
163
|
-
proc do
|
164
|
-
plain_line " {"
|
165
|
-
expected_line "- number: #<custom matcher defined from scratch with value 42>"
|
166
|
-
actual_line %|+ number: "something else"|
|
167
|
-
plain_line " }"
|
168
|
-
end
|
169
|
-
)
|
170
|
-
|
171
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
172
|
-
color_enabled
|
173
|
-
)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
@@ -1,443 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe "Integration with RSpec's #have_attributes matcher",
|
4
|
-
type: :integration do
|
5
|
-
context "when the actual value is an object" do
|
6
|
-
context "with a small set of attributes" do
|
7
|
-
context "when all of the names are methods on the actual object" do
|
8
|
-
it "produces the correct output when used in the positive" do
|
9
|
-
as_both_colored_and_uncolored do |color_enabled|
|
10
|
-
snippet = <<~TEST.strip
|
11
|
-
actual = SuperDiff::Test::Person.new(name: "a", age: 9)
|
12
|
-
expected = { name: "b" }
|
13
|
-
expect(actual).to have_attributes(expected)
|
14
|
-
TEST
|
15
|
-
program =
|
16
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
17
|
-
|
18
|
-
expected_output =
|
19
|
-
build_expected_output(
|
20
|
-
color_enabled: color_enabled,
|
21
|
-
snippet: "expect(actual).to have_attributes(expected)",
|
22
|
-
expectation:
|
23
|
-
proc do
|
24
|
-
line do
|
25
|
-
plain "Expected "
|
26
|
-
actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
|
27
|
-
plain " to have attributes "
|
28
|
-
expected %|(name: "b")|
|
29
|
-
plain "."
|
30
|
-
end
|
31
|
-
end,
|
32
|
-
diff:
|
33
|
-
proc do
|
34
|
-
plain_line " #<SuperDiff::Test::Person {"
|
35
|
-
# expected_line %|- name: "b",| # FIXME
|
36
|
-
expected_line %|- name: "b"|
|
37
|
-
actual_line %|+ name: "a",|
|
38
|
-
plain_line " age: 9"
|
39
|
-
plain_line " }>"
|
40
|
-
end
|
41
|
-
)
|
42
|
-
|
43
|
-
expect(program).to produce_output_when_run(
|
44
|
-
expected_output
|
45
|
-
).in_color(color_enabled)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "produces the correct output when used in the negative" do
|
50
|
-
as_both_colored_and_uncolored do |color_enabled|
|
51
|
-
snippet = <<~TEST.strip
|
52
|
-
actual = SuperDiff::Test::Person.new(name: "a", age: 9)
|
53
|
-
expected = { name: "a" }
|
54
|
-
expect(actual).not_to have_attributes(expected)
|
55
|
-
TEST
|
56
|
-
program =
|
57
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
58
|
-
|
59
|
-
expected_output =
|
60
|
-
build_expected_output(
|
61
|
-
color_enabled: color_enabled,
|
62
|
-
snippet: "expect(actual).not_to have_attributes(expected)",
|
63
|
-
expectation:
|
64
|
-
proc do
|
65
|
-
line do
|
66
|
-
plain "Expected "
|
67
|
-
actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
|
68
|
-
plain " not to have attributes "
|
69
|
-
expected %|(name: "a")|
|
70
|
-
plain "."
|
71
|
-
end
|
72
|
-
end
|
73
|
-
)
|
74
|
-
|
75
|
-
expect(program).to produce_output_when_run(
|
76
|
-
expected_output
|
77
|
-
).in_color(color_enabled)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when some of the names are not methods on the actual object" do
|
83
|
-
it "produces the correct output" do
|
84
|
-
as_both_colored_and_uncolored do |color_enabled|
|
85
|
-
snippet = <<~TEST.strip
|
86
|
-
actual = SuperDiff::Test::Person.new(name: "a", age: 9)
|
87
|
-
expected = { name: "b", foo: "bar" }
|
88
|
-
expect(actual).to have_attributes(expected)
|
89
|
-
TEST
|
90
|
-
program =
|
91
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
92
|
-
|
93
|
-
expected_output =
|
94
|
-
build_expected_output(
|
95
|
-
color_enabled: color_enabled,
|
96
|
-
snippet: "expect(actual).to have_attributes(expected)",
|
97
|
-
expectation:
|
98
|
-
proc do
|
99
|
-
line do
|
100
|
-
plain "Expected "
|
101
|
-
actual %|#<SuperDiff::Test::Person name: "a", age: 9>|
|
102
|
-
plain " to respond to "
|
103
|
-
expected ":foo"
|
104
|
-
plain " with "
|
105
|
-
expected "0"
|
106
|
-
plain " arguments."
|
107
|
-
end
|
108
|
-
end,
|
109
|
-
diff:
|
110
|
-
proc do
|
111
|
-
plain_line " #<SuperDiff::Test::Person {"
|
112
|
-
plain_line %| name: "a",|
|
113
|
-
# plain_line %| age: 9,| # FIXME
|
114
|
-
plain_line " age: 9"
|
115
|
-
# expected_line %|- foo: "bar"| # FIXME
|
116
|
-
expected_line %|- foo: "bar",|
|
117
|
-
plain_line " }>"
|
118
|
-
end
|
119
|
-
)
|
120
|
-
|
121
|
-
expect(program).to produce_output_when_run(
|
122
|
-
expected_output
|
123
|
-
).in_color(color_enabled)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "with a large set of attributes" do
|
130
|
-
context "when all of the names are methods on the actual object" do
|
131
|
-
it "produces the correct output when used in the positive" do
|
132
|
-
as_both_colored_and_uncolored do |color_enabled|
|
133
|
-
snippet = <<~TEST.strip
|
134
|
-
actual = SuperDiff::Test::ShippingAddress.new(
|
135
|
-
line_1: "456 Ponderosa Ct.",
|
136
|
-
line_2: nil,
|
137
|
-
city: "Hill Valley",
|
138
|
-
state: "CA",
|
139
|
-
zip: "90382"
|
140
|
-
)
|
141
|
-
expected = {
|
142
|
-
line_1: "123 Main St.",
|
143
|
-
city: "Oakland",
|
144
|
-
state: "CA",
|
145
|
-
zip: "91234"
|
146
|
-
}
|
147
|
-
expect(actual).to have_attributes(expected)
|
148
|
-
TEST
|
149
|
-
program =
|
150
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
151
|
-
|
152
|
-
expected_output =
|
153
|
-
build_expected_output(
|
154
|
-
color_enabled: color_enabled,
|
155
|
-
snippet: "expect(actual).to have_attributes(expected)",
|
156
|
-
expectation:
|
157
|
-
proc do
|
158
|
-
line do
|
159
|
-
plain " Expected "
|
160
|
-
actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
|
161
|
-
end
|
162
|
-
|
163
|
-
line do
|
164
|
-
plain "to have attributes "
|
165
|
-
expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
|
166
|
-
end
|
167
|
-
end,
|
168
|
-
diff:
|
169
|
-
proc do
|
170
|
-
plain_line " #<SuperDiff::Test::ShippingAddress {"
|
171
|
-
expected_line %|- line_1: "123 Main St.",|
|
172
|
-
actual_line %|+ line_1: "456 Ponderosa Ct.",|
|
173
|
-
plain_line " line_2: nil,"
|
174
|
-
expected_line %|- city: "Oakland",|
|
175
|
-
actual_line %|+ city: "Hill Valley",|
|
176
|
-
plain_line %| state: "CA",|
|
177
|
-
expected_line %|- zip: "91234",| # FIXME
|
178
|
-
actual_line %|+ zip: "90382"|
|
179
|
-
plain_line " }>"
|
180
|
-
end
|
181
|
-
)
|
182
|
-
|
183
|
-
expect(program).to produce_output_when_run(
|
184
|
-
expected_output
|
185
|
-
).in_color(color_enabled)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
it "produces the correct output when used in the negative" do
|
190
|
-
as_both_colored_and_uncolored do |color_enabled|
|
191
|
-
snippet = <<~TEST.strip
|
192
|
-
actual = SuperDiff::Test::ShippingAddress.new(
|
193
|
-
line_1: "123 Main St.",
|
194
|
-
line_2: nil,
|
195
|
-
city: "Oakland",
|
196
|
-
state: "CA",
|
197
|
-
zip: "91234"
|
198
|
-
)
|
199
|
-
expected = {
|
200
|
-
line_1: "123 Main St.",
|
201
|
-
city: "Oakland",
|
202
|
-
state: "CA",
|
203
|
-
zip: "91234"
|
204
|
-
}
|
205
|
-
expect(actual).not_to have_attributes(expected)
|
206
|
-
TEST
|
207
|
-
program =
|
208
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
209
|
-
|
210
|
-
expected_output =
|
211
|
-
build_expected_output(
|
212
|
-
color_enabled: color_enabled,
|
213
|
-
snippet: "expect(actual).not_to have_attributes(expected)",
|
214
|
-
newline_before_expectation: true,
|
215
|
-
expectation:
|
216
|
-
proc do
|
217
|
-
line do
|
218
|
-
plain " Expected "
|
219
|
-
actual %|#<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: nil, city: "Oakland", state: "CA", zip: "91234">|
|
220
|
-
end
|
221
|
-
|
222
|
-
line do
|
223
|
-
plain "not to have attributes "
|
224
|
-
expected %|(line_1: "123 Main St.", city: "Oakland", state: "CA", zip: "91234")|
|
225
|
-
end
|
226
|
-
end
|
227
|
-
)
|
228
|
-
|
229
|
-
expect(program).to produce_output_when_run(
|
230
|
-
expected_output
|
231
|
-
).in_color(color_enabled)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "when some of the names are not methods on the actual object" do
|
237
|
-
it "produces the correct output" do
|
238
|
-
as_both_colored_and_uncolored do |color_enabled|
|
239
|
-
snippet = <<~TEST.strip
|
240
|
-
actual = SuperDiff::Test::ShippingAddress.new(
|
241
|
-
line_1: "456 Ponderosa Ct.",
|
242
|
-
line_2: nil,
|
243
|
-
city: "Hill Valley",
|
244
|
-
state: "CA",
|
245
|
-
zip: "90382"
|
246
|
-
)
|
247
|
-
expected = {
|
248
|
-
line_1: "123 Main St.",
|
249
|
-
city: "Oakland",
|
250
|
-
state: "CA",
|
251
|
-
zip: "91234",
|
252
|
-
foo: "bar",
|
253
|
-
baz: "qux"
|
254
|
-
}
|
255
|
-
expect(actual).to have_attributes(expected)
|
256
|
-
TEST
|
257
|
-
program =
|
258
|
-
make_plain_test_program(snippet, color_enabled: color_enabled)
|
259
|
-
|
260
|
-
expected_output =
|
261
|
-
build_expected_output(
|
262
|
-
color_enabled: color_enabled,
|
263
|
-
snippet: "expect(actual).to have_attributes(expected)",
|
264
|
-
expectation:
|
265
|
-
proc do
|
266
|
-
line do
|
267
|
-
plain " Expected "
|
268
|
-
actual %|#<SuperDiff::Test::ShippingAddress line_1: "456 Ponderosa Ct.", line_2: nil, city: "Hill Valley", state: "CA", zip: "90382">|
|
269
|
-
end
|
270
|
-
|
271
|
-
line do
|
272
|
-
plain "to respond to "
|
273
|
-
expected ":foo"
|
274
|
-
plain " and "
|
275
|
-
expected ":baz"
|
276
|
-
plain " with "
|
277
|
-
expected "0"
|
278
|
-
plain " arguments"
|
279
|
-
end
|
280
|
-
end,
|
281
|
-
diff:
|
282
|
-
proc do
|
283
|
-
plain_line " #<SuperDiff::Test::ShippingAddress {"
|
284
|
-
plain_line %| line_1: "456 Ponderosa Ct.",|
|
285
|
-
plain_line " line_2: nil,"
|
286
|
-
plain_line %| city: "Hill Valley",|
|
287
|
-
plain_line %| state: "CA",|
|
288
|
-
# plain_line %| zip: "90382",| # FIXME
|
289
|
-
plain_line %| zip: "90382"|
|
290
|
-
expected_line %|- foo: "bar",|
|
291
|
-
# expected_line %|- baz: "qux"| # TODO
|
292
|
-
expected_line %|- baz: "qux",|
|
293
|
-
plain_line " }>"
|
294
|
-
end
|
295
|
-
)
|
296
|
-
|
297
|
-
expect(program).to produce_output_when_run(
|
298
|
-
expected_output
|
299
|
-
).in_color(color_enabled)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context "when the actual value is actually a hash instead of an object" do
|
307
|
-
it "displays the diff as if we were comparing hashes" do
|
308
|
-
as_both_colored_and_uncolored do |color_enabled|
|
309
|
-
snippet = <<~TEST.strip
|
310
|
-
actual = {}
|
311
|
-
expected = { name: "Elliot", age: 32 }
|
312
|
-
expect(actual).to have_attributes(expected)
|
313
|
-
TEST
|
314
|
-
|
315
|
-
program = make_plain_test_program(snippet, color_enabled: color_enabled)
|
316
|
-
|
317
|
-
expected_output =
|
318
|
-
build_expected_output(
|
319
|
-
color_enabled: color_enabled,
|
320
|
-
snippet: "expect(actual).to have_attributes(expected)",
|
321
|
-
expectation:
|
322
|
-
proc do
|
323
|
-
line do
|
324
|
-
plain "Expected "
|
325
|
-
actual "{}"
|
326
|
-
plain " to respond to "
|
327
|
-
expected ":name"
|
328
|
-
plain " and "
|
329
|
-
expected ":age"
|
330
|
-
plain " with "
|
331
|
-
expected "0"
|
332
|
-
plain " arguments."
|
333
|
-
end
|
334
|
-
end,
|
335
|
-
diff:
|
336
|
-
proc do
|
337
|
-
plain_line " {"
|
338
|
-
expected_line %|- name: "Elliot",|
|
339
|
-
expected_line "- age: 32"
|
340
|
-
plain_line " }"
|
341
|
-
end
|
342
|
-
)
|
343
|
-
|
344
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
345
|
-
color_enabled
|
346
|
-
)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
# TODO: Add as many RSpec matchers as we can here
|
351
|
-
context "that contains RSpec matchers" do
|
352
|
-
it "displays the hash correctly" do
|
353
|
-
as_both_colored_and_uncolored do |color_enabled|
|
354
|
-
snippet = <<~TEST.strip
|
355
|
-
actual = {}
|
356
|
-
expected = {
|
357
|
-
name: "Elliot",
|
358
|
-
shipping_address: an_object_having_attributes(
|
359
|
-
line_1: a_kind_of(String),
|
360
|
-
line_2: nil,
|
361
|
-
city: an_instance_of(String),
|
362
|
-
state: "CA",
|
363
|
-
zip: "91234"
|
364
|
-
),
|
365
|
-
order_ids: a_collection_including(1, 2),
|
366
|
-
data: a_hash_including(active: true),
|
367
|
-
created_at: a_value_within(1).of(Time.utc(2020, 4, 9))
|
368
|
-
}
|
369
|
-
|
370
|
-
expect(actual).to have_attributes(expected)
|
371
|
-
TEST
|
372
|
-
|
373
|
-
program =
|
374
|
-
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 have_attributes(expected)",
|
380
|
-
expectation:
|
381
|
-
proc do
|
382
|
-
line do
|
383
|
-
plain " Expected "
|
384
|
-
actual "{}"
|
385
|
-
end
|
386
|
-
|
387
|
-
line do
|
388
|
-
plain "to respond to "
|
389
|
-
expected ":name"
|
390
|
-
plain ", "
|
391
|
-
expected ":shipping_address"
|
392
|
-
plain ", "
|
393
|
-
expected ":order_ids"
|
394
|
-
plain ", "
|
395
|
-
expected ":data"
|
396
|
-
plain " and "
|
397
|
-
expected ":created_at"
|
398
|
-
plain " with "
|
399
|
-
expected "0"
|
400
|
-
plain " arguments"
|
401
|
-
end
|
402
|
-
end,
|
403
|
-
diff:
|
404
|
-
proc do
|
405
|
-
plain_line " {"
|
406
|
-
expected_line %|- name: "Elliot",|
|
407
|
-
expected_line "- shipping_address: #<an object having attributes ("
|
408
|
-
expected_line "- line_1: #<a kind of String>,"
|
409
|
-
expected_line "- line_2: nil,"
|
410
|
-
expected_line "- city: #<an instance of String>,"
|
411
|
-
expected_line %|- state: "CA",|
|
412
|
-
expected_line %|- zip: "91234"|
|
413
|
-
expected_line "- )>,"
|
414
|
-
expected_line "- order_ids: #<a collection including ("
|
415
|
-
expected_line "- 1,"
|
416
|
-
expected_line "- 2"
|
417
|
-
expected_line "- )>,"
|
418
|
-
expected_line "- data: #<a hash including ("
|
419
|
-
expected_line "- active: true"
|
420
|
-
expected_line "- )>,"
|
421
|
-
expected_line "- created_at: #<a value within 1 of #<Time {"
|
422
|
-
expected_line "- year: 2020,"
|
423
|
-
expected_line "- month: 4,"
|
424
|
-
expected_line "- day: 9,"
|
425
|
-
expected_line "- hour: 0,"
|
426
|
-
expected_line "- min: 0,"
|
427
|
-
expected_line "- sec: 0,"
|
428
|
-
expected_line "- subsec: 0,"
|
429
|
-
expected_line %|- zone: "UTC",|
|
430
|
-
expected_line "- utc_offset: 0"
|
431
|
-
expected_line "- }>>"
|
432
|
-
plain_line " }"
|
433
|
-
end
|
434
|
-
)
|
435
|
-
|
436
|
-
expect(program).to produce_output_when_run(expected_output).in_color(
|
437
|
-
color_enabled
|
438
|
-
)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
end
|
443
|
-
end
|