super_diff 0.5.3 → 0.8.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 +46 -20
- data/lib/super_diff.rb +46 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +102 -19
- data/lib/super_diff/csi.rb +1 -1
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +4 -4
- data/lib/super_diff/equality_matchers/default.rb +4 -4
- data/lib/super_diff/equality_matchers/hash.rb +4 -4
- data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/primitive.rb +6 -9
- data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/helpers.rb +52 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection.rb +12 -9
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec.rb +41 -13
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
- data/lib/super_diff/rspec/monkey_patches.rb +353 -306
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +407 -5
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
- data/spec/integration/rspec/match_matcher_spec.rb +362 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
- data/spec/spec_helper.rb +33 -13
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +8 -2
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
- data/spec/support/integration/test_programs/base.rb +38 -10
- data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
- data/spec/support/shared_examples/active_record.rb +109 -108
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +445 -465
- data/spec/unit/helpers_spec.rb +61 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1958 -0
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- data/super_diff.gemspec +1 -1
- metadata +95 -50
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
- data/spec/unit/object_inspection_spec.rb +0 -1168
@@ -3,8 +3,10 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class CollectionIncluding < SuperDiff::Differs::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
|
7
|
-
|
6
|
+
(
|
7
|
+
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
8
|
+
SuperDiff::RSpec.array_including_something?(expected)
|
9
|
+
) && actual.is_a?(::Array)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
@@ -3,8 +3,10 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class HashIncluding < SuperDiff::Differs::Hash
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
|
7
|
-
|
6
|
+
(
|
7
|
+
SuperDiff::RSpec.a_hash_including_something?(expected) ||
|
8
|
+
SuperDiff::RSpec.hash_including_something?(expected)
|
9
|
+
) && actual.is_a?(::Hash)
|
8
10
|
end
|
9
11
|
|
10
12
|
private
|
@@ -45,12 +45,12 @@ module SuperDiff
|
|
45
45
|
def add_extra_after_error
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
SuperDiff
|
48
|
+
def actual_color
|
49
|
+
SuperDiff.configuration.actual_color
|
50
50
|
end
|
51
51
|
|
52
|
-
def
|
53
|
-
SuperDiff
|
52
|
+
def expected_color
|
53
|
+
SuperDiff.configuration.expected_color
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
@@ -91,7 +91,7 @@ module SuperDiff
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def add_actual_value
|
94
|
-
template.add_text_in_color(
|
94
|
+
template.add_text_in_color(actual_color) { actual }
|
95
95
|
end
|
96
96
|
|
97
97
|
def expected_section
|
@@ -110,7 +110,7 @@ module SuperDiff
|
|
110
110
|
else
|
111
111
|
template.add_text " "
|
112
112
|
template.add_text_in_color(
|
113
|
-
|
113
|
+
expected_color,
|
114
114
|
expected_for_failure_message,
|
115
115
|
)
|
116
116
|
end
|
@@ -121,7 +121,7 @@ module SuperDiff
|
|
121
121
|
add_expected_value_to(template, expected_for_description)
|
122
122
|
else
|
123
123
|
template.add_text " "
|
124
|
-
template.add_text_in_color(
|
124
|
+
template.add_text_in_color(expected_color, expected_for_description)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -26,12 +26,12 @@ module SuperDiff
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def actual_color
|
30
30
|
:yellow
|
31
31
|
end
|
32
32
|
|
33
33
|
def add_actual_value
|
34
|
-
template.add_text_in_color(
|
34
|
+
template.add_text_in_color(actual_color) do
|
35
35
|
description_of(actual)
|
36
36
|
end
|
37
37
|
end
|
@@ -39,12 +39,12 @@ module SuperDiff
|
|
39
39
|
def add_expected_value_to_failure_message(template)
|
40
40
|
template.add_text " "
|
41
41
|
template.add_text_in_color(
|
42
|
-
|
42
|
+
expected_color,
|
43
43
|
"#{expected_for_failure_message}?",
|
44
44
|
)
|
45
45
|
template.add_text " or "
|
46
46
|
template.add_text_in_color(
|
47
|
-
|
47
|
+
expected_color,
|
48
48
|
"#{expected_for_failure_message}s?",
|
49
49
|
)
|
50
50
|
end
|
@@ -52,12 +52,12 @@ module SuperDiff
|
|
52
52
|
def add_expected_value_to_description(template)
|
53
53
|
template.add_text " "
|
54
54
|
template.add_text_in_color(
|
55
|
-
|
55
|
+
expected_color,
|
56
56
|
"`#{expected_for_description}?`",
|
57
57
|
)
|
58
58
|
template.add_text " or "
|
59
59
|
template.add_text_in_color(
|
60
|
-
|
60
|
+
expected_color,
|
61
61
|
"`#{expected_for_description}s?`",
|
62
62
|
)
|
63
63
|
end
|
@@ -20,12 +20,12 @@ module SuperDiff
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def actual_color
|
24
24
|
:yellow
|
25
25
|
end
|
26
26
|
|
27
27
|
def add_actual_value
|
28
|
-
template.add_text_in_color(
|
28
|
+
template.add_text_in_color(actual_color) do
|
29
29
|
description_of(actual)
|
30
30
|
end
|
31
31
|
end
|
@@ -33,7 +33,7 @@ module SuperDiff
|
|
33
33
|
def add_expected_value_to_failure_message(template)
|
34
34
|
template.add_text " "
|
35
35
|
template.add_text_in_color(
|
36
|
-
|
36
|
+
expected_color,
|
37
37
|
expected_for_failure_message,
|
38
38
|
)
|
39
39
|
end
|
@@ -41,7 +41,7 @@ module SuperDiff
|
|
41
41
|
def add_expected_value_to_description(template)
|
42
42
|
template.add_text " "
|
43
43
|
template.add_text_in_color(
|
44
|
-
|
44
|
+
expected_color,
|
45
45
|
"`#{expected_for_description}`",
|
46
46
|
)
|
47
47
|
end
|
@@ -20,7 +20,7 @@ module SuperDiff
|
|
20
20
|
|
21
21
|
def add_expected_value_to(template, expected)
|
22
22
|
template.add_text " "
|
23
|
-
template.add_list_in_color(
|
23
|
+
template.add_list_in_color(expected_color, expected)
|
24
24
|
end
|
25
25
|
|
26
26
|
def add_extra_after_expected_to(template)
|
@@ -57,14 +57,14 @@ module SuperDiff
|
|
57
57
|
|
58
58
|
def add_arity_clause_to(template)
|
59
59
|
template.add_text " with "
|
60
|
-
template.add_text_in_color
|
60
|
+
template.add_text_in_color expected_color, expected_arity
|
61
61
|
template.add_text " "
|
62
62
|
template.add_text pluralize("argument", expected_arity)
|
63
63
|
end
|
64
64
|
|
65
65
|
def add_arbitrary_keywords_clause_to(template)
|
66
66
|
template.add_text " with "
|
67
|
-
template.add_text_in_color
|
67
|
+
template.add_text_in_color expected_color, "any"
|
68
68
|
template.add_text " keywords"
|
69
69
|
end
|
70
70
|
|
@@ -72,7 +72,7 @@ module SuperDiff
|
|
72
72
|
template.add_text " with "
|
73
73
|
template.add_text pluralize("keyword", expected_keywords.length)
|
74
74
|
template.add_text " "
|
75
|
-
template.add_list_in_color
|
75
|
+
template.add_list_in_color expected_color, expected_keywords
|
76
76
|
end
|
77
77
|
|
78
78
|
def add_unlimited_arguments_clause_to(template)
|
@@ -82,7 +82,7 @@ module SuperDiff
|
|
82
82
|
template.add_text " with "
|
83
83
|
end
|
84
84
|
|
85
|
-
template.add_text_in_color
|
85
|
+
template.add_text_in_color expected_color, "unlimited"
|
86
86
|
template.add_text " arguments"
|
87
87
|
end
|
88
88
|
|
@@ -12,34 +12,38 @@ require "rspec/matchers/built_in/match"
|
|
12
12
|
|
13
13
|
module RSpec
|
14
14
|
module Expectations
|
15
|
-
|
16
|
-
|
15
|
+
SuperDiff.insert_singleton_overrides(self) do
|
16
|
+
def differ
|
17
|
+
SuperDiff::RSpec::Differ
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
module ExpectationHelper
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
matcher.expected_for_diff
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
SuperDiff.insert_singleton_overrides(self) do
|
23
|
+
def handle_failure(matcher, message, failure_message_method)
|
24
|
+
message = message.call if message.respond_to?(:call)
|
25
|
+
message ||= matcher.__send__(failure_message_method)
|
26
|
+
|
27
|
+
if matcher.respond_to?(:diffable?) && matcher.diffable?
|
28
|
+
# Look for expected_for_diff and actual_for_diff if possible
|
29
|
+
expected =
|
30
|
+
if matcher.respond_to?(:expected_for_diff)
|
31
|
+
matcher.expected_for_diff
|
32
|
+
else
|
33
|
+
matcher.expected
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
actual =
|
37
|
+
if matcher.respond_to?(:actual_for_diff)
|
38
|
+
matcher.actual_for_diff
|
39
|
+
else
|
40
|
+
matcher.actual
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
::RSpec::Expectations.fail_with(message, expected, actual)
|
44
|
+
else
|
45
|
+
::RSpec::Expectations.fail_with(message)
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
@@ -48,29 +52,31 @@ module RSpec
|
|
48
52
|
module Core
|
49
53
|
module Formatters
|
50
54
|
module ConsoleCodes
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if
|
57
|
-
|
58
|
-
|
59
|
-
code_or_symbol
|
60
|
-
else
|
61
|
-
RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.fetch(code_or_symbol) do
|
55
|
+
SuperDiff.insert_singleton_overrides(self) do
|
56
|
+
# Patch so it returns nothing if code_or_symbol is nil, and that it uses
|
57
|
+
# code_or_symbol if it can't be found in VT100_CODE_VALUES to allow for
|
58
|
+
# customization
|
59
|
+
def console_code_for(code_or_symbol)
|
60
|
+
if code_or_symbol
|
61
|
+
if (config_method = config_colors_to_methods[code_or_symbol])
|
62
|
+
console_code_for RSpec.configuration.__send__(config_method)
|
63
|
+
elsif RSpec::Core::Formatters::ConsoleCodes::VT100_CODE_VALUES.key?(code_or_symbol)
|
62
64
|
code_or_symbol
|
65
|
+
else
|
66
|
+
RSpec::Core::Formatters::ConsoleCodes::VT100_CODES.fetch(code_or_symbol) do
|
67
|
+
code_or_symbol
|
68
|
+
end
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
66
|
-
end
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
# Patch so it does not apply a color if code_or_symbol is nil
|
74
|
+
def wrap(text, code_or_symbol)
|
75
|
+
if RSpec.configuration.color_enabled? && code = console_code_for(code_or_symbol)
|
76
|
+
"\e[#{code}m#{text}\e[0m"
|
77
|
+
else
|
78
|
+
text
|
79
|
+
end
|
74
80
|
end
|
75
81
|
end
|
76
82
|
end
|
@@ -79,173 +85,177 @@ module RSpec
|
|
79
85
|
# UPDATE: Copy from SyntaxHighlighter::CodeRayImplementation
|
80
86
|
RESET_CODE = "\e[0m"
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
88
|
+
SuperDiff.insert_overrides(self) do
|
89
|
+
def initialize(exception, example, options={})
|
90
|
+
@exception = exception
|
91
|
+
@example = example
|
92
|
+
@message_color = options.fetch(:message_color) { RSpec.configuration.failure_color }
|
93
|
+
@description = options.fetch(:description) { example.full_description }
|
94
|
+
@detail_formatter = options.fetch(:detail_formatter) { Proc.new {} }
|
95
|
+
@extra_detail_formatter = options.fetch(:extra_detail_formatter) { Proc.new {} }
|
96
|
+
@backtrace_formatter = options.fetch(:backtrace_formatter) { RSpec.configuration.backtrace_formatter }
|
97
|
+
@indentation = options.fetch(:indentation, 2)
|
98
|
+
@skip_shared_group_trace = options.fetch(:skip_shared_group_trace, false)
|
99
|
+
# Patch to convert options[:failure_lines] to groups
|
100
|
+
if options.include?(:failure_lines)
|
101
|
+
@failure_line_groups = [
|
102
|
+
{
|
103
|
+
lines: options[:failure_lines],
|
104
|
+
already_colorized: false
|
105
|
+
}
|
106
|
+
]
|
107
|
+
end
|
100
108
|
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Override to only color uncolored lines in red
|
104
|
-
# and to not color empty lines
|
105
|
-
def colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
|
106
|
-
lines = failure_line_groups.flat_map do |group|
|
107
|
-
if group[:already_colorized]
|
108
|
-
group[:lines]
|
109
|
-
else
|
110
|
-
group[:lines].map do |line|
|
111
|
-
if line.strip.empty?
|
112
|
-
line
|
113
|
-
else
|
114
|
-
indentation = line[/^[ ]+/]
|
115
|
-
rest = colorizer.wrap(line.sub(/^[ ]+/, ''), message_color)
|
116
109
|
|
117
|
-
|
118
|
-
|
110
|
+
# Override to only color uncolored lines in red
|
111
|
+
# and to not color empty lines
|
112
|
+
def colorized_message_lines(colorizer = ::RSpec::Core::Formatters::ConsoleCodes)
|
113
|
+
lines = failure_line_groups.flat_map do |group|
|
114
|
+
if group[:already_colorized]
|
115
|
+
group[:lines]
|
116
|
+
else
|
117
|
+
group[:lines].map do |line|
|
118
|
+
if line.strip.empty?
|
119
|
+
line
|
119
120
|
else
|
120
|
-
|
121
|
+
indentation = line[/^[ ]+/]
|
122
|
+
rest = colorizer.wrap(line.sub(/^[ ]+/, ''), message_color)
|
123
|
+
|
124
|
+
if indentation
|
125
|
+
indentation + rest
|
126
|
+
else
|
127
|
+
rest
|
128
|
+
end
|
121
129
|
end
|
122
130
|
end
|
123
131
|
end
|
124
132
|
end
|
125
|
-
end
|
126
|
-
|
127
|
-
add_shared_group_lines(lines, colorizer)
|
128
|
-
end
|
129
|
-
|
130
|
-
private
|
131
|
-
|
132
|
-
def add_shared_group_lines(lines, colorizer)
|
133
|
-
return lines if @skip_shared_group_trace
|
134
133
|
|
135
|
-
|
136
|
-
# Use red instead of the default color
|
137
|
-
lines << colorizer.wrap(frame.description, :failure)
|
134
|
+
add_shared_group_lines(lines, colorizer)
|
138
135
|
end
|
139
136
|
|
140
|
-
|
141
|
-
end
|
137
|
+
private
|
142
138
|
|
143
|
-
|
144
|
-
|
145
|
-
# later
|
146
|
-
#
|
147
|
-
# TODO: Refactor this somehow
|
148
|
-
#
|
149
|
-
def failure_line_groups
|
150
|
-
if defined?(@failure_line_groups)
|
151
|
-
@failure_line_groups
|
152
|
-
else
|
153
|
-
@failure_line_groups = [
|
154
|
-
{
|
155
|
-
lines: failure_slash_error_lines,
|
156
|
-
already_colorized: true
|
157
|
-
}
|
158
|
-
]
|
159
|
-
|
160
|
-
sections = [failure_slash_error_lines, exception_lines]
|
161
|
-
separate_groups = (
|
162
|
-
sections.any? { |section| section.size > 1 } &&
|
163
|
-
!exception_lines.first.empty?
|
164
|
-
)
|
139
|
+
def add_shared_group_lines(lines, colorizer)
|
140
|
+
return lines if @skip_shared_group_trace
|
165
141
|
|
166
|
-
|
167
|
-
|
142
|
+
example.metadata[:shared_group_inclusion_backtrace].each do |frame|
|
143
|
+
# Use red instead of the default color
|
144
|
+
lines << colorizer.wrap(frame.description, :failure)
|
168
145
|
end
|
169
146
|
|
170
|
-
|
171
|
-
|
172
|
-
end
|
147
|
+
lines
|
148
|
+
end
|
173
149
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
150
|
+
# Considering that `failure_slash_error_lines` is already colored,
|
151
|
+
# extract this from the other lines so that they, too, can be colored,
|
152
|
+
# later
|
153
|
+
#
|
154
|
+
# TODO: Refactor this somehow
|
155
|
+
#
|
156
|
+
def failure_line_groups
|
157
|
+
if defined?(@failure_line_groups)
|
158
|
+
@failure_line_groups
|
179
159
|
else
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
160
|
+
@failure_line_groups = [
|
161
|
+
{
|
162
|
+
lines: failure_slash_error_lines,
|
163
|
+
already_colorized: true
|
164
|
+
}
|
165
|
+
]
|
184
166
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
167
|
+
sections = [failure_slash_error_lines, exception_lines]
|
168
|
+
separate_groups = (
|
169
|
+
sections.any? { |section| section.size > 1 } &&
|
170
|
+
!exception_lines.first.empty?
|
171
|
+
)
|
189
172
|
|
190
|
-
if
|
191
|
-
@failure_line_groups << {
|
192
|
-
|
193
|
-
|
194
|
-
|
173
|
+
if separate_groups
|
174
|
+
@failure_line_groups << { lines: [''], already_colorized: true }
|
175
|
+
end
|
176
|
+
|
177
|
+
already_colorized = exception_lines.any? do |line|
|
178
|
+
SuperDiff::Csi.already_colorized?(line)
|
179
|
+
end
|
180
|
+
|
181
|
+
if already_colorized
|
195
182
|
@failure_line_groups << {
|
196
|
-
lines: exception_lines
|
183
|
+
lines: exception_lines,
|
197
184
|
already_colorized: true
|
198
185
|
}
|
199
186
|
else
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
187
|
+
locatable_exception_lines =
|
188
|
+
exception_lines.each_with_index.map do |line, index|
|
189
|
+
{ text: line, index: index }
|
190
|
+
end
|
191
|
+
|
192
|
+
boundary_line =
|
193
|
+
locatable_exception_lines.find do |line, index|
|
194
|
+
line[:text].strip.empty? || line[:text].match?(/^ /)
|
195
|
+
end
|
196
|
+
|
197
|
+
if boundary_line
|
198
|
+
@failure_line_groups << {
|
199
|
+
lines: exception_lines[0..boundary_line[:index] - 1],
|
200
|
+
already_colorized: false
|
201
|
+
}
|
202
|
+
@failure_line_groups << {
|
203
|
+
lines: exception_lines[boundary_line[:index]..-1],
|
204
|
+
already_colorized: true
|
205
|
+
}
|
206
|
+
else
|
207
|
+
@failure_line_groups << {
|
208
|
+
lines: exception_lines,
|
209
|
+
already_colorized: false
|
210
|
+
}
|
211
|
+
end
|
204
212
|
end
|
205
|
-
end
|
206
213
|
|
207
|
-
|
214
|
+
@failure_line_groups
|
215
|
+
end
|
208
216
|
end
|
209
|
-
end
|
210
217
|
|
211
|
-
|
212
|
-
|
213
|
-
|
218
|
+
# Style the first part in white and don't style the snippet of the line
|
219
|
+
def failure_slash_error_lines
|
220
|
+
lines = read_failed_lines
|
214
221
|
|
215
|
-
|
222
|
+
failure_slash_error = ConsoleCodes.wrap("Failure/Error: ", :bold)
|
216
223
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
224
|
+
if lines.count == 1
|
225
|
+
lines[0] = failure_slash_error + lines[0].strip
|
226
|
+
else
|
227
|
+
least_indentation = SnippetExtractor.least_indentation_from(lines)
|
228
|
+
lines = lines.map do |line|
|
229
|
+
line.sub(/^#{least_indentation}/, ' ')
|
230
|
+
end
|
231
|
+
lines.unshift(failure_slash_error)
|
223
232
|
end
|
224
|
-
|
233
|
+
|
234
|
+
lines
|
225
235
|
end
|
226
236
|
|
227
|
-
|
228
|
-
|
237
|
+
# Exclude this file from being included in backtraces, so that the
|
238
|
+
# SnippetExtractor prints the right thing
|
239
|
+
def find_failed_line
|
240
|
+
line_regex = RSpec.configuration.in_project_source_dir_regex
|
241
|
+
loaded_spec_files = RSpec.configuration.loaded_spec_files
|
229
242
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
exception_backtrace.find do |line|
|
237
|
-
next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])
|
238
|
-
path = File.expand_path(line_path)
|
239
|
-
path != __FILE__ && (loaded_spec_files.include?(path) || path =~ line_regex)
|
240
|
-
end || exception_backtrace.first
|
243
|
+
exception_backtrace.find do |line|
|
244
|
+
next unless (line_path = line[/(.+?):(\d+)(|:\d+)/, 1])
|
245
|
+
path = File.expand_path(line_path)
|
246
|
+
path != __FILE__ && (loaded_spec_files.include?(path) || path =~ line_regex)
|
247
|
+
end || exception_backtrace.first
|
248
|
+
end
|
241
249
|
end
|
242
250
|
end
|
243
251
|
|
244
252
|
class SyntaxHighlighter
|
245
|
-
|
253
|
+
SuperDiff.insert_overrides(self) do
|
254
|
+
private
|
246
255
|
|
247
|
-
|
248
|
-
|
256
|
+
def implementation
|
257
|
+
RSpec::Core::Formatters::SyntaxHighlighter::NoSyntaxHighlightingImplementation
|
258
|
+
end
|
249
259
|
end
|
250
260
|
end
|
251
261
|
end
|
@@ -253,100 +263,108 @@ module RSpec
|
|
253
263
|
|
254
264
|
module Support
|
255
265
|
class ObjectFormatter
|
256
|
-
|
257
|
-
|
258
|
-
|
266
|
+
SuperDiff.insert_singleton_overrides(self) do
|
267
|
+
# Override to use our formatting algorithm
|
268
|
+
def format(value)
|
269
|
+
SuperDiff.inspect_object(value, as_lines: false)
|
270
|
+
end
|
259
271
|
end
|
260
272
|
|
261
|
-
|
262
|
-
|
263
|
-
|
273
|
+
SuperDiff.insert_overrides(self) do
|
274
|
+
# Override to use our formatting algorithm
|
275
|
+
def format(value)
|
276
|
+
SuperDiff.inspect_object(value, as_lines: false)
|
277
|
+
end
|
264
278
|
end
|
265
279
|
end
|
266
280
|
end
|
267
281
|
|
268
282
|
module Matchers
|
269
283
|
class ExpectedsForMultipleDiffs
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
284
|
+
SuperDiff.insert_singleton_overrides(self) do
|
285
|
+
# Add a key for different sides
|
286
|
+
def from(expected)
|
287
|
+
return expected if self === expected
|
288
|
+
|
289
|
+
text =
|
290
|
+
colorizer.wrap("Diff:", SuperDiff.configuration.header_color) +
|
291
|
+
"\n\n" +
|
292
|
+
colorizer.wrap(
|
293
|
+
"┌ (Key) ──────────────────────────┐",
|
294
|
+
SuperDiff.configuration.border_color
|
295
|
+
) +
|
296
|
+
"\n" +
|
297
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
298
|
+
colorizer.wrap(
|
299
|
+
"‹-› in expected, not in actual",
|
300
|
+
SuperDiff.configuration.expected_color
|
301
|
+
) +
|
302
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
303
|
+
"\n" +
|
304
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
305
|
+
colorizer.wrap(
|
306
|
+
"‹+› in actual, not in expected",
|
307
|
+
SuperDiff.configuration.actual_color
|
308
|
+
) +
|
309
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
310
|
+
"\n" +
|
311
|
+
colorizer.wrap("│ ", SuperDiff.configuration.border_color) +
|
312
|
+
"‹ › in both expected and actual" +
|
313
|
+
colorizer.wrap(" │", SuperDiff.configuration.border_color) +
|
314
|
+
"\n" +
|
315
|
+
colorizer.wrap(
|
316
|
+
"└─────────────────────────────────┘",
|
317
|
+
SuperDiff.configuration.border_color
|
318
|
+
)
|
319
|
+
|
320
|
+
new([[expected, text]])
|
321
|
+
end
|
307
322
|
|
308
|
-
|
309
|
-
|
323
|
+
def colorizer
|
324
|
+
RSpec::Core::Formatters::ConsoleCodes
|
325
|
+
end
|
310
326
|
end
|
311
327
|
|
312
|
-
|
313
|
-
|
314
|
-
|
328
|
+
SuperDiff.insert_overrides(self) do
|
329
|
+
# Add an extra line break
|
330
|
+
def message_with_diff(message, differ, actual)
|
331
|
+
diff = diffs(differ, actual)
|
315
332
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
333
|
+
if diff.empty?
|
334
|
+
message
|
335
|
+
else
|
336
|
+
"#{message.rstrip}\n\n#{diff}"
|
337
|
+
end
|
320
338
|
end
|
321
|
-
end
|
322
339
|
|
323
|
-
|
340
|
+
private
|
324
341
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
342
|
+
# Add extra line breaks in between diffs, and colorize the word "Diff"
|
343
|
+
def diffs(differ, actual)
|
344
|
+
@expected_list.map do |(expected, diff_label)|
|
345
|
+
diff = differ.diff(actual, expected)
|
346
|
+
next if diff.strip.empty?
|
347
|
+
diff_label + diff
|
348
|
+
end.compact.join("\n\n")
|
349
|
+
end
|
332
350
|
end
|
333
351
|
end
|
334
352
|
|
335
353
|
module BuiltIn
|
336
354
|
class Be
|
337
|
-
|
355
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
338
356
|
|
339
|
-
|
357
|
+
SuperDiff.insert_overrides(self) do
|
340
358
|
def expected_for_matcher_text
|
341
359
|
"truthy"
|
342
360
|
end
|
343
|
-
end
|
361
|
+
end
|
344
362
|
end
|
345
363
|
|
346
364
|
class BeComparedTo
|
347
|
-
|
365
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
348
366
|
|
349
|
-
|
367
|
+
SuperDiff.insert_overrides(self) do
|
350
368
|
def expected_action_for_matcher_text
|
351
369
|
if [:==, :===, :=~].include?(@operator)
|
352
370
|
"#{@operator}"
|
@@ -354,13 +372,13 @@ module RSpec
|
|
354
372
|
"be #{@operator}"
|
355
373
|
end
|
356
374
|
end
|
357
|
-
end
|
375
|
+
end
|
358
376
|
end
|
359
377
|
|
360
378
|
class BeFalsey
|
361
|
-
|
379
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
362
380
|
|
363
|
-
|
381
|
+
SuperDiff.insert_overrides(self) do
|
364
382
|
def expected_action_for_matcher_text
|
365
383
|
"be"
|
366
384
|
end
|
@@ -368,13 +386,13 @@ module RSpec
|
|
368
386
|
def expected_for_matcher_text
|
369
387
|
"falsey"
|
370
388
|
end
|
371
|
-
end
|
389
|
+
end
|
372
390
|
end
|
373
391
|
|
374
392
|
class BeNil
|
375
|
-
|
393
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
376
394
|
|
377
|
-
|
395
|
+
SuperDiff.insert_overrides(self) do
|
378
396
|
def expected_action_for_matcher_text
|
379
397
|
"be"
|
380
398
|
end
|
@@ -382,19 +400,23 @@ module RSpec
|
|
382
400
|
def expected_for_matcher_text
|
383
401
|
"nil"
|
384
402
|
end
|
385
|
-
end
|
403
|
+
end
|
386
404
|
end
|
387
405
|
|
388
406
|
class BePredicate
|
389
|
-
|
407
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
390
408
|
|
391
|
-
|
409
|
+
SuperDiff.insert_overrides(self) do
|
392
410
|
def actual_for_matcher_text
|
393
411
|
actual
|
394
412
|
end
|
395
413
|
|
396
414
|
def expected_for_matcher_text
|
397
|
-
|
415
|
+
if SuperDiff::RSpec.rspec_version < "3.10"
|
416
|
+
expected
|
417
|
+
else
|
418
|
+
predicate.to_s.chomp('?')
|
419
|
+
end
|
398
420
|
end
|
399
421
|
|
400
422
|
def expected_action_for_matcher_text
|
@@ -412,13 +434,13 @@ module RSpec
|
|
412
434
|
expected_predicate_method_name: predicate
|
413
435
|
)
|
414
436
|
end
|
415
|
-
end
|
437
|
+
end
|
416
438
|
end
|
417
439
|
|
418
440
|
class BeTruthy
|
419
|
-
|
441
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
420
442
|
|
421
|
-
|
443
|
+
SuperDiff.insert_overrides(self) do
|
422
444
|
def expected_action_for_matcher_text
|
423
445
|
"be"
|
424
446
|
end
|
@@ -426,13 +448,13 @@ module RSpec
|
|
426
448
|
def expected_for_matcher_text
|
427
449
|
"truthy"
|
428
450
|
end
|
429
|
-
end
|
451
|
+
end
|
430
452
|
end
|
431
453
|
|
432
454
|
class ContainExactly
|
433
|
-
|
455
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
434
456
|
|
435
|
-
|
457
|
+
SuperDiff.insert_overrides(self) do
|
436
458
|
# Override this method so that the differ knows that this is a partial
|
437
459
|
# collection
|
438
460
|
def expected_for_diff
|
@@ -448,21 +470,26 @@ module RSpec
|
|
448
470
|
def matcher_text_builder_class
|
449
471
|
SuperDiff::RSpec::MatcherTextBuilders::ContainExactly
|
450
472
|
end
|
451
|
-
end
|
473
|
+
end
|
452
474
|
end
|
453
475
|
|
454
476
|
class Eq
|
455
|
-
|
477
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
456
478
|
end
|
457
479
|
|
458
480
|
class Equal
|
459
|
-
|
481
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
460
482
|
end
|
461
483
|
|
462
484
|
class HaveAttributes
|
463
|
-
|
485
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
486
|
+
|
487
|
+
SuperDiff.insert_overrides(self) do
|
488
|
+
def initialize(*)
|
489
|
+
super
|
490
|
+
@actual = nil
|
491
|
+
end
|
464
492
|
|
465
|
-
prepend(Module.new do
|
466
493
|
# Use the message in the base matcher
|
467
494
|
def failure_message
|
468
495
|
respond_to_failure_message_or { super }
|
@@ -498,54 +525,58 @@ module RSpec
|
|
498
525
|
matchers.an_object_having_attributes(@expected)
|
499
526
|
end
|
500
527
|
end
|
501
|
-
end)
|
502
528
|
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
529
|
+
# Override to force @values to get populated so that we can show a
|
530
|
+
# proper diff
|
531
|
+
def respond_to_attributes?
|
532
|
+
cache_all_values
|
533
|
+
matches = respond_to_matcher.matches?(@actual)
|
534
|
+
@respond_to_failed = !matches
|
535
|
+
matches
|
536
|
+
end
|
511
537
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
538
|
+
# Override this method to skip non-existent attributes, and to use
|
539
|
+
# public_send
|
540
|
+
def cache_all_values
|
541
|
+
@values = @expected.keys.inject({}) do |hash, attribute_key|
|
542
|
+
if @actual.respond_to?(attribute_key)
|
543
|
+
actual_value = @actual.public_send(attribute_key)
|
544
|
+
hash.merge(attribute_key => actual_value)
|
545
|
+
else
|
546
|
+
hash
|
547
|
+
end
|
521
548
|
end
|
522
549
|
end
|
523
|
-
end
|
524
550
|
|
525
|
-
|
526
|
-
|
527
|
-
|
551
|
+
def actual_has_attribute?(attribute_key, attribute_value)
|
552
|
+
values_match?(attribute_value, @values.fetch(attribute_key))
|
553
|
+
end
|
528
554
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
555
|
+
# Override to not improve_hash_formatting
|
556
|
+
def respond_to_failure_message_or
|
557
|
+
if respond_to_failed
|
558
|
+
respond_to_matcher.failure_message
|
559
|
+
else
|
560
|
+
yield
|
561
|
+
end
|
535
562
|
end
|
536
563
|
end
|
537
564
|
end
|
538
565
|
|
539
566
|
class Has
|
540
|
-
|
567
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
541
568
|
|
542
|
-
|
569
|
+
SuperDiff.insert_overrides(self) do
|
543
570
|
def actual_for_matcher_text
|
544
571
|
actual
|
545
572
|
end
|
546
573
|
|
547
574
|
def expected_for_matcher_text
|
548
|
-
"
|
575
|
+
if SuperDiff::RSpec.rspec_version < "3.10"
|
576
|
+
"#{predicate}#{failure_message_args_description}"
|
577
|
+
else
|
578
|
+
"#{predicate}#{args_to_s}"
|
579
|
+
end
|
549
580
|
end
|
550
581
|
|
551
582
|
def expected_action_for_matcher_text
|
@@ -562,13 +593,18 @@ module RSpec
|
|
562
593
|
private_predicate: private_predicate?
|
563
594
|
)
|
564
595
|
end
|
565
|
-
end
|
596
|
+
end
|
566
597
|
end
|
567
598
|
|
568
599
|
class Include
|
569
|
-
|
600
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
601
|
+
|
602
|
+
SuperDiff.insert_overrides(self) do
|
603
|
+
def initialize(*)
|
604
|
+
super
|
605
|
+
@actual = nil
|
606
|
+
end
|
570
607
|
|
571
|
-
prepend(Module.new do
|
572
608
|
# Override this method so that the differ knows that this is a partial
|
573
609
|
# array or hash
|
574
610
|
def expected_for_diff
|
@@ -603,7 +639,11 @@ module RSpec
|
|
603
639
|
def expected_for_failure_message
|
604
640
|
# TODO: Switch to using @divergent_items and handle this in the text
|
605
641
|
# builder
|
606
|
-
|
642
|
+
if defined?(@divergent_items)
|
643
|
+
readable_list_of(@divergent_items).lstrip
|
644
|
+
else
|
645
|
+
""
|
646
|
+
end
|
607
647
|
end
|
608
648
|
|
609
649
|
# Update to use (...) as delimiter instead of {...}
|
@@ -616,13 +656,13 @@ module RSpec
|
|
616
656
|
super
|
617
657
|
end
|
618
658
|
end
|
619
|
-
end
|
659
|
+
end
|
620
660
|
end
|
621
661
|
|
622
662
|
class Match
|
623
|
-
|
663
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
624
664
|
|
625
|
-
|
665
|
+
SuperDiff.insert_overrides(self) do
|
626
666
|
def matcher_text_builder_class
|
627
667
|
SuperDiff::RSpec::MatcherTextBuilders::Match
|
628
668
|
end
|
@@ -630,7 +670,7 @@ module RSpec
|
|
630
670
|
def matcher_text_builder_args
|
631
671
|
super.merge(expected_captures: @expected_captures)
|
632
672
|
end
|
633
|
-
end
|
673
|
+
end
|
634
674
|
end
|
635
675
|
|
636
676
|
class MatchArray < ContainExactly
|
@@ -644,9 +684,9 @@ module RSpec
|
|
644
684
|
end
|
645
685
|
|
646
686
|
class RaiseError
|
647
|
-
|
687
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
648
688
|
|
649
|
-
|
689
|
+
SuperDiff.insert_overrides(self) do
|
650
690
|
def actual_for_matcher_text
|
651
691
|
if @actual_error
|
652
692
|
"#<#{@actual_error.class.name} #{@actual_error.message.inspect}>"
|
@@ -688,7 +728,7 @@ module RSpec
|
|
688
728
|
def matcher_text_builder_class
|
689
729
|
SuperDiff::RSpec::MatcherTextBuilders::RaiseError
|
690
730
|
end
|
691
|
-
end
|
731
|
+
end
|
692
732
|
|
693
733
|
def self.matcher_name
|
694
734
|
"raise error"
|
@@ -696,9 +736,9 @@ module RSpec
|
|
696
736
|
end
|
697
737
|
|
698
738
|
class RespondTo
|
699
|
-
|
739
|
+
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
700
740
|
|
701
|
-
|
741
|
+
SuperDiff.insert_overrides(self) do
|
702
742
|
def initialize(*)
|
703
743
|
super
|
704
744
|
@failing_method_names = nil
|
@@ -724,13 +764,20 @@ module RSpec
|
|
724
764
|
def expected_for_failure_message
|
725
765
|
@failing_method_names
|
726
766
|
end
|
727
|
-
end
|
767
|
+
end
|
728
768
|
end
|
729
769
|
end
|
730
770
|
|
731
|
-
|
732
|
-
|
771
|
+
SuperDiff.insert_overrides(self) do
|
772
|
+
def self.prepended(base)
|
773
|
+
base.class_eval do
|
774
|
+
alias_matcher :an_array_matching, :match_array
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
def match_array(items)
|
779
|
+
BuiltIn::MatchArray.new(items.is_a?(String) ? [items] : items)
|
780
|
+
end
|
733
781
|
end
|
734
|
-
alias_matcher :an_array_matching, :match_array
|
735
782
|
end
|
736
783
|
end
|