super_diff 0.3.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +104 -73
- data/lib/super_diff.rb +20 -11
- data/lib/super_diff/active_record.rb +21 -23
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
- data/lib/super_diff/active_record/monkey_patches.rb +9 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
- data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
- data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
- data/lib/super_diff/active_support.rb +16 -19
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
- data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
- data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/configuration.rb +60 -0
- data/lib/super_diff/csi.rb +4 -0
- data/lib/super_diff/diff_formatters.rb +3 -3
- data/lib/super_diff/diff_formatters/array.rb +3 -3
- data/lib/super_diff/diff_formatters/base.rb +3 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
- data/lib/super_diff/diff_formatters/default_object.rb +6 -8
- data/lib/super_diff/diff_formatters/defaults.rb +10 -0
- data/lib/super_diff/diff_formatters/hash.rb +3 -3
- data/lib/super_diff/diff_formatters/main.rb +41 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
- data/lib/super_diff/differs.rb +4 -11
- data/lib/super_diff/differs/array.rb +2 -11
- data/lib/super_diff/differs/base.rb +20 -3
- data/lib/super_diff/differs/custom_object.rb +2 -11
- data/lib/super_diff/differs/default_object.rb +2 -8
- data/lib/super_diff/differs/defaults.rb +12 -0
- data/lib/super_diff/differs/hash.rb +2 -11
- data/lib/super_diff/differs/main.rb +48 -0
- data/lib/super_diff/differs/multiline_string.rb +2 -14
- data/lib/super_diff/differs/time_like.rb +15 -0
- data/lib/super_diff/equality_matchers.rb +3 -9
- data/lib/super_diff/equality_matchers/array.rb +1 -7
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -8
- data/lib/super_diff/equality_matchers/defaults.rb +12 -0
- data/lib/super_diff/equality_matchers/hash.rb +1 -7
- data/lib/super_diff/equality_matchers/main.rb +21 -0
- data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
- data/lib/super_diff/errors.rb +16 -0
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
- data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
- data/lib/super_diff/implementation_checks.rb +19 -0
- data/lib/super_diff/object_inspection.rb +1 -10
- data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
- data/lib/super_diff/object_inspection/inspectors.rb +5 -1
- data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
- data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
- data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
- data/lib/super_diff/operation_tree_builders.rb +18 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
- data/lib/super_diff/operation_tree_builders/base.rb +98 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
- data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
- data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
- data/lib/super_diff/operation_tree_builders/main.rb +42 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
- data/lib/super_diff/operation_trees.rb +13 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
- data/lib/super_diff/operation_trees/base.rb +31 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
- data/lib/super_diff/operation_trees/defaults.rb +5 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
- data/lib/super_diff/operation_trees/main.rb +35 -0
- data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
- data/lib/super_diff/operations/unary_operation.rb +3 -0
- data/lib/super_diff/rspec.rb +54 -22
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +2 -17
- data/lib/super_diff/rspec/differs.rb +9 -3
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
- data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
- data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
- data/lib/super_diff/rspec/monkey_patches.rb +226 -115
- data/lib/super_diff/rspec/object_inspection.rb +0 -1
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
- data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
- data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +5 -350
- data/spec/integration/rails/active_record_spec.rb +1 -1
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
- data/spec/integration/rspec/eq_matcher_spec.rb +1 -1
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
- data/spec/integration/rspec/include_matcher_spec.rb +2 -2
- data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
- data/spec/integration/rspec/match_matcher_spec.rb +8 -8
- data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
- data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
- data/spec/spec_helper.rb +18 -7
- data/spec/support/command_runner.rb +3 -0
- data/spec/support/integration/helpers.rb +14 -90
- data/spec/support/integration/matchers.rb +143 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
- data/spec/support/integration/test_programs/base.rb +120 -0
- data/spec/support/integration/test_programs/plain.rb +13 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
- data/spec/support/models/active_record/person.rb +4 -11
- data/spec/support/models/active_record/query.rb +15 -0
- data/spec/support/models/active_record/shipping_address.rb +10 -14
- data/spec/support/object_id.rb +27 -0
- data/spec/support/ruby_versions.rb +4 -0
- data/spec/support/shared_examples/active_record.rb +71 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
- data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
- data/spec/unit/object_inspection_spec.rb +94 -18
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
- data/super_diff.gemspec +4 -6
- metadata +99 -82
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
- data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
- data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
- data/lib/super_diff/diff_formatter.rb +0 -32
- data/lib/super_diff/differ.rb +0 -51
- data/lib/super_diff/differs/time.rb +0 -24
- data/lib/super_diff/equality_matcher.rb +0 -32
- data/lib/super_diff/no_differ_available_error.rb +0 -22
- data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
- data/lib/super_diff/object_inspection/inspector.rb +0 -27
- data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
- data/lib/super_diff/object_inspection/map.rb +0 -30
- data/lib/super_diff/operation_sequences.rb +0 -9
- data/lib/super_diff/operation_sequences/base.rb +0 -11
- data/lib/super_diff/operational_sequencer.rb +0 -48
- data/lib/super_diff/operational_sequencers.rb +0 -17
- data/lib/super_diff/operational_sequencers/base.rb +0 -89
- data/lib/super_diff/operational_sequencers/hash.rb +0 -85
- data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
- data/lib/super_diff/rspec/configuration.rb +0 -31
- data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
- data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
- data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
- data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -0,0 +1,35 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTrees
|
3
|
+
class Main
|
4
|
+
extend AttrExtras.mixin
|
5
|
+
|
6
|
+
method_object :value
|
7
|
+
|
8
|
+
def call
|
9
|
+
if resolved_class
|
10
|
+
begin
|
11
|
+
resolved_class.new([], value_class: value.class)
|
12
|
+
rescue ArgumentError
|
13
|
+
resolved_class.new([])
|
14
|
+
end
|
15
|
+
else
|
16
|
+
raise Errors::NoOperationalSequenceAvailableError.create(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def resolved_class
|
23
|
+
if value.respond_to?(:attributes_for_super_diff)
|
24
|
+
CustomObject
|
25
|
+
else
|
26
|
+
available_classes.find { |klass| klass.applies_to?(value) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def available_classes
|
31
|
+
SuperDiff.configuration.extra_operation_tree_classes + DEFAULTS
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module OperationTrees
|
3
|
+
class MultilineString < Base
|
4
|
+
def self.applies_to?(value)
|
5
|
+
value.is_a?(::String) && value.is_a?(::String)
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_diff(indent_level:, collection_prefix:, add_comma:)
|
9
|
+
DiffFormatters::MultilineString.call(
|
10
|
+
self,
|
11
|
+
indent_level: indent_level,
|
12
|
+
collection_prefix: collection_prefix,
|
13
|
+
add_comma: add_comma,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -6,6 +6,7 @@ module SuperDiff
|
|
6
6
|
:collection,
|
7
7
|
:key,
|
8
8
|
:value,
|
9
|
+
# TODO: Is this even used??
|
9
10
|
:index,
|
10
11
|
:index_in_collection,
|
11
12
|
)
|
@@ -15,6 +16,7 @@ module SuperDiff
|
|
15
16
|
collection:,
|
16
17
|
key:,
|
17
18
|
value:,
|
19
|
+
# TODO: Is this even used??
|
18
20
|
index:,
|
19
21
|
index_in_collection: index
|
20
22
|
)
|
@@ -22,6 +24,7 @@ module SuperDiff
|
|
22
24
|
@collection = collection
|
23
25
|
@key = key
|
24
26
|
@value = value
|
27
|
+
# TODO: Is this even used??
|
25
28
|
@index = index
|
26
29
|
@index_in_collection = index_in_collection
|
27
30
|
end
|
data/lib/super_diff/rspec.rb
CHANGED
@@ -9,55 +9,87 @@ module SuperDiff
|
|
9
9
|
autoload :MatcherTextBuilders, "super_diff/rspec/matcher_text_builders"
|
10
10
|
autoload :MatcherTextTemplate, "super_diff/rspec/matcher_text_template"
|
11
11
|
autoload :ObjectInspection, "super_diff/rspec/object_inspection"
|
12
|
-
autoload :
|
13
|
-
|
14
|
-
class << self
|
15
|
-
attr_accessor :extra_differ_classes
|
16
|
-
attr_accessor :extra_operational_sequencer_classes
|
17
|
-
attr_accessor :extra_diff_formatter_classes
|
18
|
-
end
|
12
|
+
autoload :OperationTreeBuilders, "super_diff/rspec/operation_tree_builders"
|
19
13
|
|
20
14
|
def self.configure
|
21
15
|
yield configuration
|
22
16
|
end
|
23
17
|
|
24
18
|
def self.configuration
|
25
|
-
|
19
|
+
SuperDiff.configuration
|
26
20
|
end
|
27
21
|
|
28
|
-
def self.
|
29
|
-
|
22
|
+
def self.a_hash_including_something?(value)
|
23
|
+
fuzzy_object?(value) &&
|
30
24
|
value.respond_to?(:expecteds) &&
|
31
25
|
value.expecteds.one? &&
|
32
26
|
value.expecteds.first.is_a?(::Hash)
|
33
27
|
end
|
34
28
|
|
35
|
-
def self.
|
36
|
-
|
29
|
+
def self.a_collection_including_something?(value)
|
30
|
+
fuzzy_object?(value) &&
|
37
31
|
value.respond_to?(:expecteds) &&
|
38
32
|
!(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
|
39
33
|
end
|
40
34
|
|
41
|
-
def self.
|
42
|
-
|
35
|
+
def self.an_object_having_some_attributes?(value)
|
36
|
+
fuzzy_object?(value) &&
|
43
37
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::HaveAttributes)
|
44
38
|
end
|
45
39
|
|
46
|
-
def self.
|
47
|
-
|
40
|
+
def self.a_collection_containing_exactly_something?(value)
|
41
|
+
fuzzy_object?(value) &&
|
48
42
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::ContainExactly)
|
49
43
|
end
|
50
44
|
|
51
|
-
def self.
|
45
|
+
def self.a_kind_of_something?(value)
|
46
|
+
fuzzy_object?(value) &&
|
47
|
+
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAKindOf)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.an_instance_of_something?(value)
|
51
|
+
fuzzy_object?(value) &&
|
52
|
+
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.a_value_within_something?(value)
|
56
|
+
fuzzy_object?(value) &&
|
57
|
+
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.fuzzy_object?(value)
|
52
61
|
value.is_a?(::RSpec::Matchers::AliasedMatcher)
|
53
62
|
end
|
63
|
+
|
64
|
+
SuperDiff.configuration.tap do |config|
|
65
|
+
config.add_extra_differ_classes(
|
66
|
+
Differs::CollectionContainingExactly,
|
67
|
+
Differs::CollectionIncluding,
|
68
|
+
Differs::HashIncluding,
|
69
|
+
Differs::ObjectHavingAttributes,
|
70
|
+
)
|
71
|
+
|
72
|
+
config.add_extra_operation_tree_builder_classes(
|
73
|
+
OperationTreeBuilders::CollectionContainingExactly,
|
74
|
+
OperationTreeBuilders::CollectionIncluding,
|
75
|
+
OperationTreeBuilders::HashIncluding,
|
76
|
+
OperationTreeBuilders::ObjectHavingAttributes,
|
77
|
+
)
|
78
|
+
|
79
|
+
config.add_extra_inspector_classes(
|
80
|
+
ObjectInspection::Inspectors::CollectionContainingExactly,
|
81
|
+
ObjectInspection::Inspectors::CollectionIncluding,
|
82
|
+
ObjectInspection::Inspectors::HashIncluding,
|
83
|
+
ObjectInspection::Inspectors::InstanceOf,
|
84
|
+
ObjectInspection::Inspectors::KindOf,
|
85
|
+
ObjectInspection::Inspectors::ObjectHavingAttributes,
|
86
|
+
ObjectInspection::Inspectors::Primitive,
|
87
|
+
ObjectInspection::Inspectors::ValueWithin,
|
88
|
+
)
|
89
|
+
end
|
54
90
|
end
|
55
91
|
end
|
56
92
|
|
57
93
|
require_relative "rspec/monkey_patches"
|
58
94
|
|
59
|
-
SuperDiff::
|
60
|
-
SuperDiff::RSpec::ObjectInspection::MapExtension,
|
61
|
-
)
|
62
|
-
|
63
|
-
SuperDiff::Csi.color_enabled = RSpec.configuration.color_enabled?
|
95
|
+
SuperDiff::Csi.color_enabled = ::RSpec.configuration.color_enabled?
|
@@ -7,31 +7,16 @@ module SuperDiff
|
|
7
7
|
|
8
8
|
def diff
|
9
9
|
if worth_diffing?
|
10
|
-
diff = SuperDiff::
|
10
|
+
diff = SuperDiff::Differs::Main.call(
|
11
11
|
expected,
|
12
12
|
actual,
|
13
13
|
omit_empty: true,
|
14
|
-
extra_classes: [
|
15
|
-
*RSpec.configuration.extra_differ_classes,
|
16
|
-
Differs::CollectionContainingExactly,
|
17
|
-
Differs::PartialArray,
|
18
|
-
Differs::PartialHash,
|
19
|
-
Differs::PartialObject,
|
20
|
-
],
|
21
|
-
extra_operational_sequencer_classes: [
|
22
|
-
*RSpec.configuration.extra_operational_sequencer_classes,
|
23
|
-
OperationalSequencers::CollectionContainingExactly,
|
24
|
-
OperationalSequencers::PartialArray,
|
25
|
-
OperationalSequencers::PartialHash,
|
26
|
-
OperationalSequencers::PartialObject,
|
27
|
-
],
|
28
|
-
extra_diff_formatter_classes: RSpec.configuration.extra_diff_formatter_classes,
|
29
14
|
)
|
30
15
|
"\n\n" + diff
|
31
16
|
else
|
32
17
|
""
|
33
18
|
end
|
34
|
-
rescue NoDifferAvailableError
|
19
|
+
rescue SuperDiff::Errors::NoDifferAvailableError
|
35
20
|
""
|
36
21
|
end
|
37
22
|
|
@@ -5,9 +5,15 @@ module SuperDiff
|
|
5
5
|
:CollectionContainingExactly,
|
6
6
|
"super_diff/rspec/differs/collection_containing_exactly",
|
7
7
|
)
|
8
|
-
autoload
|
9
|
-
|
10
|
-
|
8
|
+
autoload(
|
9
|
+
:CollectionIncluding,
|
10
|
+
"super_diff/rspec/differs/collection_including",
|
11
|
+
)
|
12
|
+
autoload :HashIncluding, "super_diff/rspec/differs/hash_including"
|
13
|
+
autoload(
|
14
|
+
:ObjectHavingAttributes,
|
15
|
+
"super_diff/rspec/differs/object_having_attributes",
|
16
|
+
)
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
@@ -3,19 +3,14 @@ module SuperDiff
|
|
3
3
|
module Differs
|
4
4
|
class CollectionContainingExactly < SuperDiff::Differs::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
SuperDiff::RSpec.
|
6
|
+
SuperDiff::RSpec.a_collection_containing_exactly_something?(expected) &&
|
7
7
|
actual.is_a?(::Array)
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
expected: expected,
|
15
|
-
actual: actual,
|
16
|
-
extra_operational_sequencer_classes: extra_operational_sequencer_classes,
|
17
|
-
extra_diff_formatter_classes: extra_diff_formatter_classes,
|
18
|
-
)
|
12
|
+
def operation_tree_builder_class
|
13
|
+
OperationTreeBuilders::CollectionContainingExactly
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module Differs
|
4
|
+
class CollectionIncluding < SuperDiff::Differs::Array
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
SuperDiff::RSpec.a_collection_including_something?(expected) &&
|
7
|
+
actual.is_a?(::Array)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def operation_tree_builder_class
|
13
|
+
OperationTreeBuilders::CollectionIncluding
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module Differs
|
4
|
+
class HashIncluding < SuperDiff::Differs::Hash
|
5
|
+
def self.applies_to?(expected, actual)
|
6
|
+
SuperDiff::RSpec.a_hash_including_something?(expected) &&
|
7
|
+
actual.is_a?(::Hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def operation_tree_builder_class
|
13
|
+
OperationTreeBuilders::HashIncluding
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module Differs
|
4
|
+
class ObjectHavingAttributes < SuperDiff::Differs::DefaultObject
|
5
|
+
def self.applies_to?(expected, _actual)
|
6
|
+
SuperDiff::RSpec.an_object_having_some_attributes?(expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def operation_tree_builder_class
|
12
|
+
OperationTreeBuilders::ObjectHavingAttributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -10,6 +10,10 @@ module SuperDiff
|
|
10
10
|
:ContainExactly,
|
11
11
|
"super_diff/rspec/matcher_text_builders/contain_exactly",
|
12
12
|
)
|
13
|
+
autoload(
|
14
|
+
:HavePredicate,
|
15
|
+
"super_diff/rspec/matcher_text_builders/have_predicate",
|
16
|
+
)
|
13
17
|
autoload :Match, "super_diff/rspec/matcher_text_builders/match"
|
14
18
|
autoload(
|
15
19
|
:RaiseError,
|
@@ -36,27 +36,46 @@ module SuperDiff
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def add_expected_value_to_failure_message(template)
|
40
40
|
template.add_text " "
|
41
|
-
template.add_text_in_color(
|
41
|
+
template.add_text_in_color(
|
42
|
+
alpha_color,
|
43
|
+
"#{expected_for_failure_message}?",
|
44
|
+
)
|
42
45
|
template.add_text " or "
|
43
|
-
template.add_text_in_color(
|
46
|
+
template.add_text_in_color(
|
47
|
+
alpha_color,
|
48
|
+
"#{expected_for_failure_message}s?",
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_expected_value_to_description(template)
|
53
|
+
template.add_text " "
|
54
|
+
template.add_text_in_color(
|
55
|
+
alpha_color,
|
56
|
+
"`#{expected_for_description}?`",
|
57
|
+
)
|
58
|
+
template.add_text " or "
|
59
|
+
template.add_text_in_color(
|
60
|
+
alpha_color,
|
61
|
+
"`#{expected_for_description}s?`",
|
62
|
+
)
|
44
63
|
end
|
45
64
|
|
46
65
|
def add_extra_after_error
|
47
66
|
if expected_predicate_method_name == :true?
|
48
67
|
template.add_text "\n\n"
|
49
68
|
template.add_text "(Perhaps you want to use "
|
50
|
-
template.add_text_in_color(:blue, "
|
69
|
+
template.add_text_in_color(:blue, "be(true)")
|
51
70
|
template.add_text " or "
|
52
|
-
template.add_text_in_color(:blue, "
|
71
|
+
template.add_text_in_color(:blue, "be_truthy")
|
53
72
|
template.add_text " instead?)"
|
54
73
|
elsif expected_predicate_method_name == :false?
|
55
74
|
template.add_text "\n\n"
|
56
75
|
template.add_text "(Perhaps you want to use "
|
57
|
-
template.add_text_in_color(:blue, "
|
76
|
+
template.add_text_in_color(:blue, "be(false)")
|
58
77
|
template.add_text " or "
|
59
|
-
template.add_text_in_color(:blue, "
|
78
|
+
template.add_text_in_color(:blue, "be_falsey")
|
60
79
|
template.add_text " instead?)"
|
61
80
|
end
|
62
81
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module MatcherTextBuilders
|
4
|
+
class HavePredicate < Base
|
5
|
+
def initialize(predicate_accessible:, private_predicate:, **rest)
|
6
|
+
super(**rest)
|
7
|
+
@predicate_accessible = predicate_accessible
|
8
|
+
@private_predicate = private_predicate
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def expected_action_for_failure_message
|
14
|
+
if predicate_accessible?
|
15
|
+
"return a truthy result for"
|
16
|
+
elsif private_predicate?
|
17
|
+
"have a public method"
|
18
|
+
else
|
19
|
+
"respond to"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def beta_color
|
24
|
+
:yellow
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_actual_value
|
28
|
+
template.add_text_in_color(beta_color) do
|
29
|
+
description_of(actual)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_expected_value_to_failure_message(template)
|
34
|
+
template.add_text " "
|
35
|
+
template.add_text_in_color(
|
36
|
+
alpha_color,
|
37
|
+
expected_for_failure_message,
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_expected_value_to_description(template)
|
42
|
+
template.add_text " "
|
43
|
+
template.add_text_in_color(
|
44
|
+
alpha_color,
|
45
|
+
"`#{expected_for_description}`",
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def private_predicate?
|
52
|
+
@private_predicate
|
53
|
+
end
|
54
|
+
|
55
|
+
def predicate_accessible?
|
56
|
+
@predicate_accessible
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|