super_diff 0.9.0 → 0.11.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 +65 -26
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/differs.rb +1 -1
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +22 -18
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +14 -7
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/object_inspection.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -2
- data/lib/super_diff/active_record/operation_tree_builders.rb +2 -2
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_record/operation_trees.rb +1 -1
- data/lib/super_diff/active_record.rb +7 -15
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/differs.rb +1 -1
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +20 -11
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +5 -1
- data/lib/super_diff/active_support/object_inspection.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +5 -6
- data/lib/super_diff/active_support/operation_tree_builders.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +1 -1
- data/lib/super_diff/active_support/operation_trees.rb +1 -1
- data/lib/super_diff/active_support.rb +6 -10
- data/lib/super_diff/colorized_document_extensions.rb +2 -4
- data/lib/super_diff/configuration.rb +14 -8
- data/lib/super_diff/csi/color.rb +4 -4
- data/lib/super_diff/csi/colorized_document.rb +12 -16
- data/lib/super_diff/csi/document.rb +8 -19
- data/lib/super_diff/csi/eight_bit_color.rb +19 -19
- data/lib/super_diff/csi/four_bit_color.rb +82 -31
- data/lib/super_diff/csi/twenty_four_bit_color.rb +12 -11
- data/lib/super_diff/csi/uncolorized_document.rb +2 -6
- data/lib/super_diff/csi.rb +10 -14
- data/lib/super_diff/diff_formatters/collection.rb +35 -41
- data/lib/super_diff/differs/date_like.rb +15 -0
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/defaults.rb +2 -1
- data/lib/super_diff/differs/main.rb +2 -13
- data/lib/super_diff/differs.rb +1 -0
- data/lib/super_diff/equality_matchers/array.rb +10 -12
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +2 -4
- data/lib/super_diff/equality_matchers/defaults.rb +1 -1
- data/lib/super_diff/equality_matchers/hash.rb +10 -12
- data/lib/super_diff/equality_matchers/multiline_string.rb +11 -13
- data/lib/super_diff/equality_matchers/primitive.rb +10 -12
- data/lib/super_diff/equality_matchers/singleline_string.rb +10 -12
- data/lib/super_diff/equality_matchers.rb +1 -1
- data/lib/super_diff/errors.rb +2 -6
- data/lib/super_diff/gem_version.rb +3 -3
- data/lib/super_diff/helpers.rb +10 -10
- data/lib/super_diff/implementation_checks.rb +2 -2
- data/lib/super_diff/line.rb +3 -3
- data/lib/super_diff/object_inspection/inspection_tree.rb +64 -73
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +29 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +17 -13
- data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +43 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +2 -1
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +35 -18
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +30 -36
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +11 -22
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +3 -7
- data/lib/super_diff/object_inspection/nodes/base.rb +9 -14
- data/lib/super_diff/object_inspection/nodes/inspection.rb +26 -34
- data/lib/super_diff/object_inspection/nodes/nesting.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/only_when.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/text.rb +1 -5
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +2 -6
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +1 -1
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +1 -5
- data/lib/super_diff/object_inspection/nodes.rb +7 -7
- data/lib/super_diff/object_inspection.rb +3 -3
- data/lib/super_diff/operation_tree_builders/array.rb +12 -11
- data/lib/super_diff/operation_tree_builders/base.rb +17 -15
- data/lib/super_diff/operation_tree_builders/custom_object.rb +8 -6
- data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
- data/lib/super_diff/operation_tree_builders/default_object.rb +29 -21
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +23 -24
- data/lib/super_diff/operation_tree_builders/main.rb +4 -11
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +1 -11
- data/lib/super_diff/operation_tree_builders.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners/base.rb +1 -5
- data/lib/super_diff/operation_tree_flatteners/collection.rb +13 -16
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +1 -2
- data/lib/super_diff/operation_tree_flatteners/hash.rb +2 -10
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +2 -1
- data/lib/super_diff/operation_tree_flatteners.rb +3 -3
- data/lib/super_diff/operation_trees/base.rb +3 -5
- data/lib/super_diff/operation_trees/default_object.rb +1 -3
- data/lib/super_diff/operations/binary_operation.rb +2 -2
- data/lib/super_diff/operations/unary_operation.rb +1 -1
- data/lib/super_diff/rails.rb +2 -1
- data/lib/super_diff/recursion_guard.rb +5 -4
- data/lib/super_diff/rspec/augmented_matcher.rb +4 -5
- data/lib/super_diff/rspec/differ.rb +6 -13
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -2
- data/lib/super_diff/rspec/differs/collection_including.rb +1 -1
- data/lib/super_diff/rspec/differs/hash_including.rb +1 -1
- data/lib/super_diff/rspec/differs.rb +3 -3
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +13 -15
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +5 -7
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +3 -5
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +2 -10
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +2 -6
- data/lib/super_diff/rspec/matcher_text_builders.rb +5 -8
- data/lib/super_diff/rspec/matcher_text_template.rb +13 -16
- data/lib/super_diff/rspec/monkey_patches.rb +180 -123
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +21 -13
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +35 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +21 -15
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +11 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +13 -9
- data/lib/super_diff/rspec/object_inspection.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +7 -6
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +11 -10
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +22 -17
- data/lib/super_diff/rspec/operation_tree_builders.rb +4 -4
- data/lib/super_diff/rspec.rb +17 -18
- data/lib/super_diff/tiered_lines_elider.rb +87 -115
- data/lib/super_diff/tiered_lines_formatter.rb +5 -9
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +13 -9
- data/spec/examples.txt +541 -483
- data/spec/integration/rails/active_record_spec.rb +3 -1
- data/spec/integration/rails/engines_spec.rb +25 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +3 -1
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +40 -35
- data/spec/integration/rspec/be_matcher_spec.rb +360 -320
- data/spec/integration/rspec/be_nil_matcher_spec.rb +38 -34
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +376 -359
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +38 -33
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +257 -254
- data/spec/integration/rspec/eq_matcher_spec.rb +695 -585
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +312 -304
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +291 -297
- data/spec/integration/rspec/include_matcher_spec.rb +327 -225
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +294 -291
- data/spec/integration/rspec/match_matcher_spec.rb +916 -903
- data/spec/integration/rspec/raise_error_matcher_spec.rb +1208 -449
- data/spec/integration/rspec/respond_to_matcher_spec.rb +702 -697
- data/spec/integration/rspec/third_party_matcher_spec.rb +142 -138
- data/spec/integration/rspec/unhandled_errors_spec.rb +88 -84
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +20 -20
- data/spec/support/command_runner.rb +34 -57
- data/spec/support/integration/helpers.rb +44 -32
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +28 -23
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +17 -22
- data/spec/support/integration/test_programs/plain.rb +6 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +4 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails.rb +4 -1
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +20 -0
- data/spec/support/models/active_record/person.rb +6 -4
- data/spec/support/models/active_record/shipping_address.rb +9 -10
- data/spec/support/models/customer.rb +2 -4
- data/spec/support/models/player.rb +3 -6
- data/spec/support/models/shipping_address.rb +4 -13
- data/spec/support/shared_examples/active_record.rb +258 -240
- data/spec/support/shared_examples/active_support.rb +174 -51
- data/spec/support/shared_examples/elided_diffs.rb +447 -423
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +500 -464
- data/spec/support/shared_examples/key.rb +123 -0
- data/spec/support/unit/helpers.rb +1 -3
- data/spec/support/unit/matchers/match_output.rb +12 -13
- data/spec/unit/active_record/object_inspection_spec.rb +222 -206
- data/spec/unit/active_support/object_inspection_spec.rb +170 -0
- data/spec/unit/equality_matchers/main_spec.rb +1049 -984
- data/spec/unit/helpers_spec.rb +14 -21
- data/spec/unit/operation_tree_flatteners/array_spec.rb +557 -524
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +619 -601
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +619 -621
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +595 -556
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +102 -92
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +3 -3
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +3 -3
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +1 -1
- data/spec/unit/rspec/matchers/have_predicate_spec.rb +2 -2
- data/spec/unit/rspec/matchers/include_spec.rb +2 -2
- data/spec/unit/rspec/matchers/match_array_spec.rb +2 -2
- data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/matchers/respond_to_spec.rb +23 -16
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +351 -326
- data/spec/unit/super_diff_spec.rb +1594 -1437
- data/spec/unit/tiered_lines_elider_spec.rb +3508 -3536
- data/spec/unit/tiered_lines_formatter_spec.rb +54 -116
- data/super_diff.gemspec +13 -12
- metadata +88 -75
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
- data/spec/tmp/warnings_logger/all_warnings.txt +0 -2
data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module ObjectInspection
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
class GenericDescribableMatcher < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
|
+
def self.applies_to?(value)
|
7
|
+
::RSpec::Matchers.is_a_describable_matcher?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
t1.add_text "#<#{object.description}>"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,28 +4,34 @@ module SuperDiff
|
|
4
4
|
module InspectionTreeBuilders
|
5
5
|
class HashIncluding < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
|
-
SuperDiff::RSpec.a_hash_including_something?(value) ||
|
7
|
+
SuperDiff::RSpec.a_hash_including_something?(value) ||
|
8
|
+
SuperDiff::RSpec.hash_including_something?(value)
|
8
9
|
end
|
9
10
|
|
10
11
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
12
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
13
|
+
# stree-ignore
|
14
|
+
t1.as_lines_when_rendering_to_lines(
|
15
|
+
collection_bookend: :open
|
16
|
+
) do |t2|
|
17
|
+
t2.add_text "#<a hash including ("
|
14
18
|
end
|
15
19
|
|
16
|
-
nested do |
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
insert_hash_inspection_of(hash)
|
20
|
+
t1.nested do |t2|
|
21
|
+
if SuperDiff::RSpec.a_hash_including_something?(object)
|
22
|
+
t2.insert_hash_inspection_of(object.expecteds.first)
|
23
|
+
else
|
24
|
+
t2.insert_hash_inspection_of(
|
25
|
+
object.instance_variable_get(:@expected)
|
26
|
+
)
|
27
|
+
end
|
25
28
|
end
|
26
29
|
|
27
|
-
|
28
|
-
|
30
|
+
# stree-ignore
|
31
|
+
t1.as_lines_when_rendering_to_lines(
|
32
|
+
collection_bookend: :close
|
33
|
+
) do |t2|
|
34
|
+
t2.add_text ")>"
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
@@ -4,19 +4,20 @@ module SuperDiff
|
|
4
4
|
module InspectionTreeBuilders
|
5
5
|
class InstanceOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
|
-
SuperDiff::RSpec.an_instance_of_something?(value) ||
|
7
|
+
SuperDiff::RSpec.an_instance_of_something?(value) ||
|
8
|
+
SuperDiff::RSpec.instance_of_something?(value)
|
8
9
|
end
|
9
10
|
|
10
11
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
13
|
+
klass =
|
14
|
+
if SuperDiff::RSpec.an_instance_of_something?(object)
|
15
|
+
object.expected
|
16
|
+
else
|
17
|
+
object.instance_variable_get(:@klass)
|
18
|
+
end
|
19
|
+
|
20
|
+
t1.add_text "#<an instance of #{klass}>"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -4,19 +4,20 @@ module SuperDiff
|
|
4
4
|
module InspectionTreeBuilders
|
5
5
|
class KindOf < SuperDiff::ObjectInspection::InspectionTreeBuilders::Base
|
6
6
|
def self.applies_to?(value)
|
7
|
-
SuperDiff::RSpec.a_kind_of_something?(value) ||
|
7
|
+
SuperDiff::RSpec.a_kind_of_something?(value) ||
|
8
|
+
SuperDiff::RSpec.kind_of_something?(value)
|
8
9
|
end
|
9
10
|
|
10
11
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
13
|
+
klass =
|
14
|
+
if SuperDiff::RSpec.a_kind_of_something?(object)
|
15
|
+
object.expected
|
16
|
+
else
|
17
|
+
object.instance_variable_get(:@klass)
|
18
|
+
end
|
19
|
+
|
20
|
+
t1.add_text "#<a kind of #{klass}>"
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb
CHANGED
@@ -8,17 +8,24 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
|
13
|
-
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
# stree-ignore
|
13
|
+
t1.as_lines_when_rendering_to_lines(
|
14
|
+
collection_bookend: :open
|
15
|
+
) do |t2|
|
16
|
+
t2.add_text "#<an object having attributes ("
|
14
17
|
end
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
# stree-ignore
|
20
|
+
t1.nested do |t2|
|
21
|
+
t2.insert_hash_inspection_of(object.expected)
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
# stree-ignore
|
25
|
+
t1.as_lines_when_rendering_to_lines(
|
26
|
+
collection_bookend: :close
|
27
|
+
) do |t2|
|
28
|
+
t2.add_text ")>"
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -8,22 +8,21 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call
|
11
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
12
|
-
as_prelude_when_rendering_to_lines do
|
13
|
-
add_text "#<a value within "
|
11
|
+
SuperDiff::ObjectInspection::InspectionTree.new do |t1|
|
12
|
+
t1.as_prelude_when_rendering_to_lines do |t2|
|
13
|
+
t2.add_text "#<a value within "
|
14
14
|
|
15
|
-
add_inspection_of
|
16
|
-
|
17
|
-
|
15
|
+
t2.add_inspection_of(
|
16
|
+
object.base_matcher.instance_variable_get("@delta"),
|
17
|
+
as_lines: false
|
18
|
+
)
|
18
19
|
|
19
|
-
add_text " of "
|
20
|
+
t2.add_text " of "
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
add_inspection_of { |aliased_matcher| aliased_matcher.expected }
|
24
|
-
# rubocop:enable Style/SymbolProc
|
23
|
+
t1.add_inspection_of object.expected
|
25
24
|
|
26
|
-
add_text ">"
|
25
|
+
t1.add_text ">"
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -4,39 +4,43 @@ module SuperDiff
|
|
4
4
|
module InspectionTreeBuilders
|
5
5
|
autoload(
|
6
6
|
:CollectionContainingExactly,
|
7
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly"
|
7
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly"
|
8
8
|
)
|
9
9
|
autoload(
|
10
10
|
:CollectionIncluding,
|
11
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/collection_including"
|
11
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/collection_including"
|
12
12
|
)
|
13
13
|
autoload(
|
14
14
|
:Double,
|
15
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/double"
|
15
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/double"
|
16
|
+
)
|
17
|
+
autoload(
|
18
|
+
:GenericDescribableMatcher,
|
19
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher"
|
16
20
|
)
|
17
21
|
autoload(
|
18
22
|
:HashIncluding,
|
19
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/hash_including"
|
23
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/hash_including"
|
20
24
|
)
|
21
25
|
autoload(
|
22
26
|
:InstanceOf,
|
23
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/instance_of"
|
27
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/instance_of"
|
24
28
|
)
|
25
29
|
autoload(
|
26
30
|
:KindOf,
|
27
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/kind_of"
|
31
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/kind_of"
|
28
32
|
)
|
29
33
|
autoload(
|
30
34
|
:ObjectHavingAttributes,
|
31
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes"
|
35
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes"
|
32
36
|
)
|
33
37
|
autoload(
|
34
38
|
:Primitive,
|
35
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/primitive"
|
39
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/primitive"
|
36
40
|
)
|
37
41
|
autoload(
|
38
42
|
:ValueWithin,
|
39
|
-
"super_diff/rspec/object_inspection/inspection_tree_builders/value_within"
|
43
|
+
"super_diff/rspec/object_inspection/inspection_tree_builders/value_within"
|
40
44
|
)
|
41
45
|
end
|
42
46
|
end
|
@@ -3,8 +3,9 @@ module SuperDiff
|
|
3
3
|
module OperationTreeBuilders
|
4
4
|
class CollectionContainingExactly < SuperDiff::OperationTreeBuilders::Base
|
5
5
|
def self.applies_to?(expected, actual)
|
6
|
-
SuperDiff::RSpec.a_collection_containing_exactly_something?(
|
7
|
-
|
6
|
+
SuperDiff::RSpec.a_collection_containing_exactly_something?(
|
7
|
+
expected
|
8
|
+
) && actual.is_a?(::Array)
|
8
9
|
end
|
9
10
|
|
10
11
|
def initialize(actual:, **)
|
@@ -17,11 +18,11 @@ module SuperDiff
|
|
17
18
|
def unary_operations
|
18
19
|
operations = []
|
19
20
|
|
20
|
-
(0...actual.length)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
(0...actual.length)
|
22
|
+
.reject do |index|
|
23
|
+
indexes_in_actual_but_not_in_expected.include?(index)
|
24
|
+
end
|
25
|
+
.each { |index| add_noop_to(operations, index) }
|
25
26
|
|
26
27
|
indexes_in_actual_but_not_in_expected.each do |index|
|
27
28
|
add_insert_to(operations, index)
|
@@ -51,7 +52,7 @@ module SuperDiff
|
|
51
52
|
collection: collection,
|
52
53
|
key: index,
|
53
54
|
value: value,
|
54
|
-
index: index
|
55
|
+
index: index
|
55
56
|
)
|
56
57
|
end
|
57
58
|
|
@@ -62,7 +63,7 @@ module SuperDiff
|
|
62
63
|
collection: collection,
|
63
64
|
key: index,
|
64
65
|
value: value,
|
65
|
-
index: index
|
66
|
+
index: index
|
66
67
|
)
|
67
68
|
end
|
68
69
|
|
@@ -73,7 +74,7 @@ module SuperDiff
|
|
73
74
|
collection: collection,
|
74
75
|
key: index,
|
75
76
|
value: value,
|
76
|
-
index: index
|
77
|
+
index: index
|
77
78
|
)
|
78
79
|
end
|
79
80
|
|
@@ -5,7 +5,7 @@ module SuperDiff
|
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
8
|
-
|
8
|
+
SuperDiff::RSpec.array_including_something?(expected)
|
9
9
|
) && actual.is_a?(::Array)
|
10
10
|
end
|
11
11
|
|
@@ -18,11 +18,12 @@ module SuperDiff
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def actual_with_extra_items_in_expected_at_end
|
21
|
-
value =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
value =
|
22
|
+
if SuperDiff::RSpec.a_collection_including_something?(expected)
|
23
|
+
expected.expecteds
|
24
|
+
else
|
25
|
+
expected.instance_variable_get(:@expected)
|
26
|
+
end
|
26
27
|
actual + (value - actual)
|
27
28
|
end
|
28
29
|
end
|
@@ -2,29 +2,30 @@ module SuperDiff
|
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
4
|
class HashIncluding < SuperDiff::OperationTreeBuilders::Hash
|
5
|
+
include ::RSpec::Matchers::Composable
|
6
|
+
|
5
7
|
def self.applies_to?(expected, actual)
|
6
8
|
(
|
7
9
|
SuperDiff::RSpec.a_hash_including_something?(expected) ||
|
8
|
-
|
10
|
+
SuperDiff::RSpec.hash_including_something?(expected)
|
9
11
|
) && actual.is_a?(::Hash)
|
10
12
|
end
|
11
13
|
|
12
14
|
def initialize(expected:, **rest)
|
13
|
-
hash =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
hash =
|
16
|
+
if SuperDiff::RSpec.a_hash_including_something?(expected)
|
17
|
+
expected.expecteds.first
|
18
|
+
else
|
19
|
+
expected.instance_variable_get(:@expected)
|
20
|
+
end
|
18
21
|
super(expected: hash, **rest)
|
19
22
|
end
|
20
23
|
|
21
24
|
private
|
22
25
|
|
23
26
|
def should_add_noop_operation?(key)
|
24
|
-
!expected.include?(key) ||
|
25
|
-
actual.include?(key) &&
|
26
|
-
expected[key] == actual[key]
|
27
|
-
)
|
27
|
+
!expected.include?(key) ||
|
28
|
+
(actual.include?(key) && values_match?(expected[key], actual[key]))
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -23,34 +23,39 @@ module SuperDiff
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def establish_expected_and_actual_attributes
|
26
|
-
@expected_attributes =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
@expected_attributes =
|
27
|
+
attribute_names.reduce({}) do |hash, name|
|
28
|
+
if expected.expected.include?(name)
|
29
|
+
hash.merge(name => expected.expected[name])
|
30
|
+
else
|
31
|
+
hash
|
32
|
+
end
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
@actual_attributes =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
@actual_attributes =
|
36
|
+
attribute_names.reduce({}) do |hash, name|
|
37
|
+
if actual.respond_to?(name)
|
38
|
+
hash.merge(name => actual.public_send(name))
|
39
|
+
else
|
40
|
+
hash
|
41
|
+
end
|
39
42
|
end
|
40
|
-
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def should_add_noop_operation?(attribute_name)
|
44
|
-
!expected_attributes.include?(attribute_name) ||
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
!expected_attributes.include?(attribute_name) ||
|
47
|
+
(
|
48
|
+
actual_attributes.include?(attribute_name) &&
|
49
|
+
expected_attributes[attribute_name] ==
|
50
|
+
actual_attributes[attribute_name]
|
51
|
+
)
|
48
52
|
end
|
49
53
|
|
50
54
|
def should_add_insert_operation?(attribute_name)
|
51
55
|
expected_attributes.include?(attribute_name) &&
|
52
56
|
actual_attributes.include?(attribute_name) &&
|
53
|
-
expected_attributes[attribute_name] !=
|
57
|
+
expected_attributes[attribute_name] !=
|
58
|
+
actual_attributes[attribute_name]
|
54
59
|
end
|
55
60
|
end
|
56
61
|
end
|
@@ -3,19 +3,19 @@ module SuperDiff
|
|
3
3
|
module OperationTreeBuilders
|
4
4
|
autoload(
|
5
5
|
:CollectionContainingExactly,
|
6
|
-
"super_diff/rspec/operation_tree_builders/collection_containing_exactly"
|
6
|
+
"super_diff/rspec/operation_tree_builders/collection_containing_exactly"
|
7
7
|
)
|
8
8
|
autoload(
|
9
9
|
:CollectionIncluding,
|
10
|
-
"super_diff/rspec/operation_tree_builders/collection_including"
|
10
|
+
"super_diff/rspec/operation_tree_builders/collection_including"
|
11
11
|
)
|
12
12
|
autoload(
|
13
13
|
:HashIncluding,
|
14
|
-
"super_diff/rspec/operation_tree_builders/hash_including"
|
14
|
+
"super_diff/rspec/operation_tree_builders/hash_including"
|
15
15
|
)
|
16
16
|
autoload(
|
17
17
|
:ObjectHavingAttributes,
|
18
|
-
"super_diff/rspec/operation_tree_builders/object_having_attributes"
|
18
|
+
"super_diff/rspec/operation_tree_builders/object_having_attributes"
|
19
19
|
)
|
20
20
|
end
|
21
21
|
end
|
data/lib/super_diff/rspec.rb
CHANGED
@@ -20,10 +20,8 @@ module SuperDiff
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.a_hash_including_something?(value)
|
23
|
-
|
24
|
-
value.
|
25
|
-
value.expecteds.one? &&
|
26
|
-
value.expecteds.first.is_a?(::Hash)
|
23
|
+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
|
24
|
+
value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
|
27
25
|
end
|
28
26
|
|
29
27
|
# HINT: `a_hash_including` is an alias of `include` in the rspec-expectations gem.
|
@@ -33,8 +31,7 @@ module SuperDiff
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def self.a_collection_including_something?(value)
|
36
|
-
|
37
|
-
value.respond_to?(:expecteds) &&
|
34
|
+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
|
38
35
|
!(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
|
39
36
|
end
|
40
37
|
|
@@ -43,17 +40,17 @@ module SuperDiff
|
|
43
40
|
end
|
44
41
|
|
45
42
|
def self.an_object_having_some_attributes?(value)
|
46
|
-
|
43
|
+
aliased_matcher?(value) &&
|
47
44
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::HaveAttributes)
|
48
45
|
end
|
49
46
|
|
50
47
|
def self.a_collection_containing_exactly_something?(value)
|
51
|
-
|
48
|
+
aliased_matcher?(value) &&
|
52
49
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::ContainExactly)
|
53
50
|
end
|
54
51
|
|
55
52
|
def self.a_kind_of_something?(value)
|
56
|
-
|
53
|
+
aliased_matcher?(value) &&
|
57
54
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAKindOf)
|
58
55
|
end
|
59
56
|
|
@@ -64,7 +61,7 @@ module SuperDiff
|
|
64
61
|
end
|
65
62
|
|
66
63
|
def self.an_instance_of_something?(value)
|
67
|
-
|
64
|
+
aliased_matcher?(value) &&
|
68
65
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
|
69
66
|
end
|
70
67
|
|
@@ -75,19 +72,20 @@ module SuperDiff
|
|
75
72
|
end
|
76
73
|
|
77
74
|
def self.a_value_within_something?(value)
|
78
|
-
|
75
|
+
aliased_matcher?(value) &&
|
79
76
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
|
80
77
|
end
|
81
78
|
|
82
|
-
def self.
|
79
|
+
def self.aliased_matcher?(value)
|
83
80
|
value.is_a?(::RSpec::Matchers::AliasedMatcher)
|
84
81
|
end
|
85
82
|
|
86
83
|
def self.rspec_version
|
87
|
-
@_rspec_version ||=
|
88
|
-
|
89
|
-
|
90
|
-
|
84
|
+
@_rspec_version ||=
|
85
|
+
begin
|
86
|
+
require "rspec/core/version"
|
87
|
+
GemVersion.new(::RSpec::Core::Version::STRING)
|
88
|
+
end
|
91
89
|
end
|
92
90
|
|
93
91
|
SuperDiff.configuration.tap do |config|
|
@@ -95,14 +93,14 @@ module SuperDiff
|
|
95
93
|
Differs::CollectionContainingExactly,
|
96
94
|
Differs::CollectionIncluding,
|
97
95
|
Differs::HashIncluding,
|
98
|
-
Differs::ObjectHavingAttributes
|
96
|
+
Differs::ObjectHavingAttributes
|
99
97
|
)
|
100
98
|
|
101
99
|
config.add_extra_operation_tree_builder_classes(
|
102
100
|
OperationTreeBuilders::CollectionContainingExactly,
|
103
101
|
OperationTreeBuilders::CollectionIncluding,
|
104
102
|
OperationTreeBuilders::HashIncluding,
|
105
|
-
OperationTreeBuilders::ObjectHavingAttributes
|
103
|
+
OperationTreeBuilders::ObjectHavingAttributes
|
106
104
|
)
|
107
105
|
|
108
106
|
config.add_extra_inspection_tree_builder_classes(
|
@@ -115,6 +113,7 @@ module SuperDiff
|
|
115
113
|
ObjectInspection::InspectionTreeBuilders::ObjectHavingAttributes,
|
116
114
|
# ObjectInspection::InspectionTreeBuilders::Primitive,
|
117
115
|
ObjectInspection::InspectionTreeBuilders::ValueWithin,
|
116
|
+
ObjectInspection::InspectionTreeBuilders::GenericDescribableMatcher
|
118
117
|
)
|
119
118
|
end
|
120
119
|
end
|