super_diff 0.10.0 → 0.12.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 +19 -166
- data/lib/super_diff/active_record/differs/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb +57 -0
- data/lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb +34 -0
- data/lib/super_diff/active_record/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/monkey_patches.rb +6 -3
- data/lib/super_diff/active_record/object_inspection.rb +16 -4
- data/lib/super_diff/active_record/operation_tree_builders/active_record_model.rb +6 -2
- data/lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +1 -1
- data/lib/super_diff/active_record.rb +12 -16
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb +44 -0
- data/lib/super_diff/active_support/inspection_tree_builders.rb +14 -0
- data/lib/super_diff/active_support/object_inspection.rb +16 -4
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +1 -1
- data/lib/super_diff/active_support.rb +11 -14
- data/lib/super_diff/basic/diff_formatters/collection.rb +135 -0
- data/lib/super_diff/basic/diff_formatters/multiline_string.rb +34 -0
- data/lib/super_diff/basic/diff_formatters.rb +11 -0
- data/lib/super_diff/basic/differs/array.rb +17 -0
- data/lib/super_diff/basic/differs/custom_object.rb +19 -0
- data/lib/super_diff/basic/differs/date_like.rb +17 -0
- data/lib/super_diff/basic/differs/default_object.rb +24 -0
- data/lib/super_diff/basic/differs/hash.rb +17 -0
- data/lib/super_diff/basic/differs/multiline_string.rb +18 -0
- data/lib/super_diff/basic/differs/time_like.rb +17 -0
- data/lib/super_diff/basic/differs.rb +24 -0
- data/lib/super_diff/basic/inspection_tree_builders/array.rb +53 -0
- data/lib/super_diff/basic/inspection_tree_builders/custom_object.rb +41 -0
- data/lib/super_diff/basic/inspection_tree_builders/date_like.rb +51 -0
- data/lib/super_diff/basic/inspection_tree_builders/default_object.rb +77 -0
- data/lib/super_diff/basic/inspection_tree_builders/hash.rb +63 -0
- data/lib/super_diff/basic/inspection_tree_builders/primitive.rb +19 -0
- data/lib/super_diff/basic/inspection_tree_builders/time_like.rb +58 -0
- data/lib/super_diff/basic/inspection_tree_builders.rb +20 -0
- data/lib/super_diff/basic/operation_tree_builders/array.rb +111 -0
- data/lib/super_diff/basic/operation_tree_builders/custom_object.rb +42 -0
- data/lib/super_diff/basic/operation_tree_builders/date_like.rb +17 -0
- data/lib/super_diff/basic/operation_tree_builders/default_object.rb +117 -0
- data/lib/super_diff/basic/operation_tree_builders/hash.rb +222 -0
- data/lib/super_diff/basic/operation_tree_builders/multiline_string.rb +90 -0
- data/lib/super_diff/basic/operation_tree_builders/time_like.rb +26 -0
- data/lib/super_diff/basic/operation_tree_builders.rb +34 -0
- data/lib/super_diff/basic/operation_tree_flatteners/array.rb +17 -0
- data/lib/super_diff/basic/operation_tree_flatteners/collection.rb +140 -0
- data/lib/super_diff/basic/operation_tree_flatteners/custom_object.rb +30 -0
- data/lib/super_diff/basic/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/basic/operation_tree_flatteners/hash.rb +35 -0
- data/lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb +20 -0
- data/lib/super_diff/basic/operation_tree_flatteners.rb +24 -0
- data/lib/super_diff/basic/operation_trees/array.rb +17 -0
- data/lib/super_diff/basic/operation_trees/custom_object.rb +17 -0
- data/lib/super_diff/basic/operation_trees/default_object.rb +42 -0
- data/lib/super_diff/basic/operation_trees/hash.rb +17 -0
- data/lib/super_diff/basic/operation_trees/multiline_string.rb +17 -0
- data/lib/super_diff/basic/operation_trees.rb +25 -0
- data/lib/super_diff/basic.rb +48 -0
- data/lib/super_diff/{differs/base.rb → core/abstract_differ.rb} +2 -2
- data/lib/super_diff/core/abstract_inspection_tree_builder.rb +26 -0
- data/lib/super_diff/{operation_trees/base.rb → core/abstract_operation_tree.rb} +6 -2
- data/lib/super_diff/{operation_tree_builders/base.rb → core/abstract_operation_tree_builder.rb} +4 -8
- data/lib/super_diff/{operation_tree_flatteners/base.rb → core/abstract_operation_tree_flattener.rb} +2 -2
- data/lib/super_diff/{operations → core}/binary_operation.rb +1 -1
- data/lib/super_diff/core/colorized_document_extensions.rb +20 -0
- data/lib/super_diff/core/configuration.rb +192 -0
- data/lib/super_diff/core/differ_dispatcher.rb +31 -0
- data/lib/super_diff/core/gem_version.rb +47 -0
- data/lib/super_diff/core/helpers.rb +88 -0
- data/lib/super_diff/core/implementation_checks.rb +21 -0
- data/lib/super_diff/{object_inspection → core}/inspection_tree.rb +32 -26
- data/lib/super_diff/core/inspection_tree_builder_dispatcher.rb +23 -0
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_lines_when_rendering_to_lines.rb +12 -5
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prefix_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_prelude_when_rendering_to_lines.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/as_single_line.rb +3 -3
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/base.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/inspection.rb +7 -11
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/nesting.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/only_when.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/text.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_non_empty.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_lines.rb +2 -2
- data/lib/super_diff/{object_inspection/nodes → core/inspection_tree_nodes}/when_rendering_to_string.rb +2 -2
- data/lib/super_diff/core/inspection_tree_nodes.rb +55 -0
- data/lib/super_diff/core/line.rb +85 -0
- data/lib/super_diff/{errors → core}/no_differ_available_error.rb +1 -1
- data/lib/super_diff/core/no_inspection_tree_builder_available_error.rb +21 -0
- data/lib/super_diff/core/no_operation_tree_available_error.rb +20 -0
- data/lib/super_diff/{errors/no_operational_sequencer_available_error.rb → core/no_operation_tree_builder_available_error.rb} +6 -4
- data/lib/super_diff/{operation_tree_builders/main.rb → core/operation_tree_builder_dispatcher.rb} +9 -13
- data/lib/super_diff/core/operation_tree_finder.rb +27 -0
- data/lib/super_diff/core/prefix_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/prelude_for_next_inspection_tree_node.rb +6 -0
- data/lib/super_diff/core/recursion_guard.rb +52 -0
- data/lib/super_diff/core/tiered_lines.rb +6 -0
- data/lib/super_diff/core/tiered_lines_elider.rb +472 -0
- data/lib/super_diff/core/tiered_lines_formatter.rb +77 -0
- data/lib/super_diff/{operations → core}/unary_operation.rb +1 -1
- data/lib/super_diff/core.rb +69 -0
- data/lib/super_diff/differs.rb +19 -11
- data/lib/super_diff/equality_matchers/array.rb +3 -3
- data/lib/super_diff/equality_matchers/default.rb +8 -3
- data/lib/super_diff/equality_matchers/hash.rb +3 -3
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -3
- data/lib/super_diff/equality_matchers/primitive.rb +3 -3
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +12 -12
- data/lib/super_diff/object_inspection.rb +63 -14
- data/lib/super_diff/operation_tree_builders.rb +19 -14
- data/lib/super_diff/operation_tree_flatteners.rb +19 -16
- data/lib/super_diff/operation_trees.rb +19 -9
- data/lib/super_diff/operations.rb +12 -2
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +4 -5
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +1 -1
- 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/object_having_attributes.rb +1 -1
- data/lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/collection_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/double.rb +100 -0
- data/lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb +17 -0
- data/lib/super_diff/rspec/inspection_tree_builders/hash_including.rb +40 -0
- data/lib/super_diff/rspec/inspection_tree_builders/instance_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/kind_of.rb +25 -0
- data/lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb +34 -0
- data/lib/super_diff/rspec/inspection_tree_builders/primitive.rb +9 -0
- data/lib/super_diff/rspec/inspection_tree_builders/value_within.rb +30 -0
- data/lib/super_diff/rspec/inspection_tree_builders.rb +40 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
- data/lib/super_diff/rspec/monkey_patches.rb +59 -8
- data/lib/super_diff/rspec/object_inspection.rb +14 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +4 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +1 -1
- data/lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb +2 -2
- data/lib/super_diff/rspec.rb +28 -25
- data/lib/super_diff/version.rb +1 -1
- data/lib/super_diff.rb +78 -21
- data/spec/examples.txt +704 -493
- data/spec/integration/rails/engines_spec.rb +8 -3
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
- data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
- data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
- data/spec/integration/rspec/include_matcher_spec.rb +23 -23
- data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
- data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
- data/spec/integration/rspec/match_matcher_spec.rb +93 -93
- data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
- data/spec/internal/log/test.log +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/integration/helpers.rb +19 -11
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +1 -1
- data/spec/support/integration/matchers.rb +34 -0
- data/spec/support/integration/test_programs/base.rb +6 -6
- data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
- data/spec/support/models/active_record/person.rb +8 -1
- data/spec/support/shared_examples/active_record.rb +38 -38
- data/spec/support/shared_examples/active_support.rb +125 -4
- data/spec/support/shared_examples/elided_diffs.rb +48 -48
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
- data/spec/support/shared_examples/key.rb +10 -10
- data/spec/support/unit/helpers.rb +12 -1
- data/spec/support/unit/matchers/be_deprecated_in_favor_of.rb +39 -0
- data/spec/unit/active_record/object_inspection_spec.rb +5 -5
- data/spec/unit/active_support/object_inspection_spec.rb +170 -0
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/array_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/custom_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/default_object_spec.rb +9 -9
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/hash_spec.rb +8 -8
- data/spec/unit/{operation_tree_flatteners → basic/operation_tree_flatteners}/multiline_string_spec.rb +4 -4
- data/spec/unit/{helpers_spec.rb → core/helpers_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_elider_spec.rb → core/tiered_lines_elider_spec.rb} +2 -2
- data/spec/unit/{tiered_lines_formatter_spec.rb → core/tiered_lines_formatter_spec.rb} +1 -1
- data/spec/unit/deprecations_spec.rb +176 -0
- data/spec/unit/equality_matchers/main_spec.rb +5 -5
- data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
- data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
- data/spec/unit/rspec/object_inspection_spec.rb +2 -2
- data/spec/unit/super_diff_spec.rb +64 -0
- data/super_diff.gemspec +6 -0
- metadata +137 -112
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +0 -39
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +0 -27
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +0 -16
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +0 -31
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +0 -12
- data/lib/super_diff/colorized_document_extensions.rb +0 -18
- data/lib/super_diff/configuration.rb +0 -149
- data/lib/super_diff/diff_formatters/collection.rb +0 -132
- data/lib/super_diff/diff_formatters/multiline_string.rb +0 -31
- data/lib/super_diff/differs/array.rb +0 -15
- data/lib/super_diff/differs/custom_object.rb +0 -17
- data/lib/super_diff/differs/default_object.rb +0 -19
- data/lib/super_diff/differs/defaults.rb +0 -12
- data/lib/super_diff/differs/empty.rb +0 -13
- data/lib/super_diff/differs/hash.rb +0 -15
- data/lib/super_diff/differs/main.rb +0 -31
- data/lib/super_diff/differs/multiline_string.rb +0 -16
- data/lib/super_diff/differs/time_like.rb +0 -15
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
- data/lib/super_diff/gem_version.rb +0 -45
- data/lib/super_diff/helpers.rb +0 -86
- data/lib/super_diff/implementation_checks.rb +0 -19
- data/lib/super_diff/line.rb +0 -83
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +0 -34
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +0 -27
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +0 -31
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +0 -54
- data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +0 -14
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +0 -38
- data/lib/super_diff/object_inspection/inspection_tree_builders/main.rb +0 -30
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +0 -21
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +0 -47
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +0 -44
- data/lib/super_diff/object_inspection/nodes.rb +0 -50
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +0 -6
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +0 -6
- data/lib/super_diff/operation_tree_builders/array.rb +0 -107
- data/lib/super_diff/operation_tree_builders/custom_object.rb +0 -40
- data/lib/super_diff/operation_tree_builders/default_object.rb +0 -119
- data/lib/super_diff/operation_tree_builders/defaults.rb +0 -5
- data/lib/super_diff/operation_tree_builders/hash.rb +0 -218
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +0 -86
- data/lib/super_diff/operation_tree_builders/time_like.rb +0 -24
- data/lib/super_diff/operation_tree_flatteners/array.rb +0 -15
- data/lib/super_diff/operation_tree_flatteners/collection.rb +0 -136
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +0 -28
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +0 -31
- data/lib/super_diff/operation_tree_flatteners/hash.rb +0 -33
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +0 -18
- data/lib/super_diff/operation_trees/array.rb +0 -15
- data/lib/super_diff/operation_trees/custom_object.rb +0 -15
- data/lib/super_diff/operation_trees/default_object.rb +0 -40
- data/lib/super_diff/operation_trees/defaults.rb +0 -5
- data/lib/super_diff/operation_trees/hash.rb +0 -15
- data/lib/super_diff/operation_trees/main.rb +0 -35
- data/lib/super_diff/operation_trees/multiline_string.rb +0 -15
- data/lib/super_diff/recursion_guard.rb +0 -50
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +0 -29
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +0 -36
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +0 -98
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +0 -37
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +0 -29
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +0 -10
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +0 -33
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +0 -44
- data/lib/super_diff/tiered_lines.rb +0 -4
- data/lib/super_diff/tiered_lines_elider.rb +0 -462
- data/lib/super_diff/tiered_lines_formatter.rb +0 -75
@@ -0,0 +1,40 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class HashIncluding < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff::RSpec.a_hash_including_something?(value) ||
|
7
|
+
SuperDiff::RSpec.hash_including_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
Core::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 "#<a hash including ("
|
17
|
+
end
|
18
|
+
|
19
|
+
t1.nested do |t2|
|
20
|
+
if SuperDiff::RSpec.a_hash_including_something?(object)
|
21
|
+
t2.insert_hash_inspection_of(object.expecteds.first)
|
22
|
+
else
|
23
|
+
t2.insert_hash_inspection_of(
|
24
|
+
object.instance_variable_get(:@expected)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# stree-ignore
|
30
|
+
t1.as_lines_when_rendering_to_lines(
|
31
|
+
collection_bookend: :close
|
32
|
+
) do |t2|
|
33
|
+
t2.add_text ")>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class InstanceOf < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff::RSpec.an_instance_of_something?(value) ||
|
7
|
+
SuperDiff::RSpec.instance_of_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
Core::InspectionTree.new do |t1|
|
12
|
+
klass =
|
13
|
+
if SuperDiff::RSpec.an_instance_of_something?(object)
|
14
|
+
object.expected
|
15
|
+
else
|
16
|
+
object.instance_variable_get(:@klass)
|
17
|
+
end
|
18
|
+
|
19
|
+
t1.add_text "#<an instance of #{klass}>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class KindOf < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff::RSpec.a_kind_of_something?(value) ||
|
7
|
+
SuperDiff::RSpec.kind_of_something?(value)
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
Core::InspectionTree.new do |t1|
|
12
|
+
klass =
|
13
|
+
if SuperDiff::RSpec.a_kind_of_something?(object)
|
14
|
+
object.expected
|
15
|
+
else
|
16
|
+
object.instance_variable_get(:@klass)
|
17
|
+
end
|
18
|
+
|
19
|
+
t1.add_text "#<a kind of #{klass}>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class ObjectHavingAttributes < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff::RSpec.an_object_having_some_attributes?(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
|
+
# stree-ignore
|
12
|
+
t1.as_lines_when_rendering_to_lines(
|
13
|
+
collection_bookend: :open
|
14
|
+
) do |t2|
|
15
|
+
t2.add_text "#<an object having attributes ("
|
16
|
+
end
|
17
|
+
|
18
|
+
# stree-ignore
|
19
|
+
t1.nested do |t2|
|
20
|
+
t2.insert_hash_inspection_of(object.expected)
|
21
|
+
end
|
22
|
+
|
23
|
+
# stree-ignore
|
24
|
+
t1.as_lines_when_rendering_to_lines(
|
25
|
+
collection_bookend: :close
|
26
|
+
) do |t2|
|
27
|
+
t2.add_text ")>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
class ValueWithin < Core::AbstractInspectionTreeBuilder
|
5
|
+
def self.applies_to?(value)
|
6
|
+
SuperDiff::RSpec.a_value_within_something?(value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
Core::InspectionTree.new do |t1|
|
11
|
+
t1.as_prelude_when_rendering_to_lines do |t2|
|
12
|
+
t2.add_text "#<a value within "
|
13
|
+
|
14
|
+
t2.add_inspection_of(
|
15
|
+
object.base_matcher.instance_variable_get("@delta"),
|
16
|
+
as_lines: false
|
17
|
+
)
|
18
|
+
|
19
|
+
t2.add_text " of "
|
20
|
+
end
|
21
|
+
|
22
|
+
t1.add_inspection_of object.expected
|
23
|
+
|
24
|
+
t1.add_text ">"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SuperDiff
|
2
|
+
module RSpec
|
3
|
+
module InspectionTreeBuilders
|
4
|
+
autoload(
|
5
|
+
:CollectionContainingExactly,
|
6
|
+
"super_diff/rspec/inspection_tree_builders/collection_containing_exactly"
|
7
|
+
)
|
8
|
+
autoload(
|
9
|
+
:CollectionIncluding,
|
10
|
+
"super_diff/rspec/inspection_tree_builders/collection_including"
|
11
|
+
)
|
12
|
+
autoload :Double, "super_diff/rspec/inspection_tree_builders/double"
|
13
|
+
autoload(
|
14
|
+
:GenericDescribableMatcher,
|
15
|
+
"super_diff/rspec/inspection_tree_builders/generic_describable_matcher"
|
16
|
+
)
|
17
|
+
autoload(
|
18
|
+
:HashIncluding,
|
19
|
+
"super_diff/rspec/inspection_tree_builders/hash_including"
|
20
|
+
)
|
21
|
+
autoload(
|
22
|
+
:InstanceOf,
|
23
|
+
"super_diff/rspec/inspection_tree_builders/instance_of"
|
24
|
+
)
|
25
|
+
autoload :KindOf, "super_diff/rspec/inspection_tree_builders/kind_of"
|
26
|
+
autoload(
|
27
|
+
:ObjectHavingAttributes,
|
28
|
+
"super_diff/rspec/inspection_tree_builders/object_having_attributes"
|
29
|
+
)
|
30
|
+
autoload(
|
31
|
+
:Primitive,
|
32
|
+
"super_diff/rspec/inspection_tree_builders/primitive"
|
33
|
+
)
|
34
|
+
autoload(
|
35
|
+
:ValueWithin,
|
36
|
+
"super_diff/rspec/inspection_tree_builders/value_within"
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -5,14 +5,10 @@ module SuperDiff
|
|
5
5
|
protected
|
6
6
|
|
7
7
|
def actual_phrase
|
8
|
-
actual
|
9
|
-
|
10
|
-
|
11
|
-
def add_actual_value
|
12
|
-
if actual
|
13
|
-
template.add_text_in_color(actual_color) { actual }
|
8
|
+
if actual == "exception-free block"
|
9
|
+
"Expected"
|
14
10
|
else
|
15
|
-
|
11
|
+
"Expected raised exception"
|
16
12
|
end
|
17
13
|
end
|
18
14
|
end
|
@@ -218,7 +218,10 @@ module RSpec
|
|
218
218
|
}
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
221
|
+
@failure_line_groups << {
|
222
|
+
lines: extra_failure_lines,
|
223
|
+
already_colorized: true
|
224
|
+
}
|
222
225
|
@failure_line_groups
|
223
226
|
end
|
224
227
|
end
|
@@ -241,6 +244,24 @@ module RSpec
|
|
241
244
|
lines
|
242
245
|
end
|
243
246
|
|
247
|
+
# Override to ensure that each item in the array returned is one and
|
248
|
+
# only one line and doesn't contain any newline characters
|
249
|
+
def extra_failure_lines
|
250
|
+
@extra_failure_lines ||=
|
251
|
+
begin
|
252
|
+
original_lines = Array(example.metadata[:extra_failure_lines])
|
253
|
+
normalized_lines =
|
254
|
+
original_lines.flat_map { |line| line.split("\n") }
|
255
|
+
unless normalized_lines.empty?
|
256
|
+
unless normalized_lines.first == ""
|
257
|
+
normalized_lines.unshift("")
|
258
|
+
end
|
259
|
+
normalized_lines.push("") unless normalized_lines.last == ""
|
260
|
+
end
|
261
|
+
normalized_lines
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
244
265
|
# Exclude this file from being included in backtraces, so that the
|
245
266
|
# SnippetExtractor prints the right thing
|
246
267
|
def find_failed_line
|
@@ -701,9 +722,15 @@ module RSpec
|
|
701
722
|
SuperDiff.insert_overrides(self, SuperDiff::RSpec::AugmentedMatcher)
|
702
723
|
|
703
724
|
SuperDiff.insert_overrides(self) do
|
725
|
+
def expected_action_for_description
|
726
|
+
"raise"
|
727
|
+
end
|
728
|
+
|
704
729
|
def actual_for_matcher_text
|
705
730
|
if @actual_error
|
706
731
|
"#<#{@actual_error.class.name} #{@actual_error.message.inspect}>"
|
732
|
+
else
|
733
|
+
"exception-free block"
|
707
734
|
end
|
708
735
|
end
|
709
736
|
|
@@ -712,12 +739,19 @@ module RSpec
|
|
712
739
|
end
|
713
740
|
|
714
741
|
def expected_for_matcher_text
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
742
|
+
case @expected_message
|
743
|
+
when nil
|
744
|
+
if RSpec::Matchers.is_a_describable_matcher?(@expected_error)
|
745
|
+
description_of(@expected_error)
|
746
|
+
elsif @expected_error.is_a?(Regexp)
|
747
|
+
"a kind of Exception with message matching #{description_of(@expected_error)}"
|
748
|
+
else
|
749
|
+
"a kind of #{@expected_error}"
|
750
|
+
end
|
751
|
+
when Regexp
|
752
|
+
"#{described_expected_error} with message matching #{description_of(@expected_message)}"
|
719
753
|
else
|
720
|
-
"
|
754
|
+
"#{described_expected_error} with message #{description_of(@expected_message)}"
|
721
755
|
end
|
722
756
|
end
|
723
757
|
|
@@ -730,12 +764,22 @@ module RSpec
|
|
730
764
|
end
|
731
765
|
|
732
766
|
def expected_action_for_failure_message
|
733
|
-
@actual_error ? "match" : "raise
|
767
|
+
@actual_error ? "match" : "raise"
|
734
768
|
end
|
735
769
|
|
736
770
|
def matcher_text_builder_class
|
737
771
|
SuperDiff::RSpec::MatcherTextBuilders::RaiseError
|
738
772
|
end
|
773
|
+
|
774
|
+
private
|
775
|
+
|
776
|
+
def described_expected_error
|
777
|
+
if @expected_error.is_a?(Class)
|
778
|
+
"a kind of #{@expected_error}"
|
779
|
+
else
|
780
|
+
description_of(@expected_error)
|
781
|
+
end
|
782
|
+
end
|
739
783
|
end
|
740
784
|
|
741
785
|
def self.matcher_name
|
@@ -782,7 +826,14 @@ module RSpec
|
|
782
826
|
end
|
783
827
|
|
784
828
|
def match_array(items)
|
785
|
-
|
829
|
+
# This is a bit strange, but this is fundamentally different from
|
830
|
+
# splatting `items` in the argument list. It's functionally equivalent
|
831
|
+
# to, though not quite the same as:
|
832
|
+
#
|
833
|
+
# items.is_a?(Array) ? items : [items]
|
834
|
+
#
|
835
|
+
items = *items
|
836
|
+
BuiltIn::MatchArray.new(items)
|
786
837
|
end
|
787
838
|
end
|
788
839
|
end
|
@@ -1,10 +1,20 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module ObjectInspection
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module InspectionTreeBuilders
|
5
|
+
def self.const_missing(missing_const_name)
|
6
|
+
if RSpec::InspectionTreeBuilders.const_defined?(missing_const_name)
|
7
|
+
warn <<~EOT
|
8
|
+
WARNING: SuperDiff::RSpec::ObjectInspection::InspectionTreeBuilders::#{missing_const_name} is deprecated and will be removed in the next major release.
|
9
|
+
Please use SuperDiff::RSpec::InspectionTreeBuilders::#{missing_const_name} instead.
|
10
|
+
#{caller_locations.join("\n")}
|
11
|
+
EOT
|
12
|
+
RSpec::InspectionTreeBuilders.const_get(missing_const_name)
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class CollectionContainingExactly <
|
4
|
+
class CollectionContainingExactly < Core::AbstractOperationTreeBuilder
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
SuperDiff::RSpec.a_collection_containing_exactly_something?(
|
7
7
|
expected
|
@@ -47,7 +47,7 @@ module SuperDiff
|
|
47
47
|
|
48
48
|
def add_noop_to(operations, index)
|
49
49
|
value = actual[index]
|
50
|
-
operations << ::
|
50
|
+
operations << Core::UnaryOperation.new(
|
51
51
|
name: :noop,
|
52
52
|
collection: collection,
|
53
53
|
key: index,
|
@@ -58,7 +58,7 @@ module SuperDiff
|
|
58
58
|
|
59
59
|
def add_delete_to(operations, index)
|
60
60
|
value = expected.expected[index]
|
61
|
-
operations << ::
|
61
|
+
operations << Core::UnaryOperation.new(
|
62
62
|
name: :delete,
|
63
63
|
collection: collection,
|
64
64
|
key: index,
|
@@ -69,7 +69,7 @@ module SuperDiff
|
|
69
69
|
|
70
70
|
def add_insert_to(operations, index)
|
71
71
|
value = actual[index]
|
72
|
-
operations << ::
|
72
|
+
operations << Core::UnaryOperation.new(
|
73
73
|
name: :insert,
|
74
74
|
collection: collection,
|
75
75
|
key: index,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class CollectionIncluding <
|
4
|
+
class CollectionIncluding < Basic::OperationTreeBuilders::Array
|
5
5
|
def self.applies_to?(expected, actual)
|
6
6
|
(
|
7
7
|
SuperDiff::RSpec.a_collection_including_something?(expected) ||
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class HashIncluding <
|
4
|
+
class HashIncluding < Basic::OperationTreeBuilders::Hash
|
5
5
|
include ::RSpec::Matchers::Composable
|
6
6
|
|
7
7
|
def self.applies_to?(expected, actual)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SuperDiff
|
2
2
|
module RSpec
|
3
3
|
module OperationTreeBuilders
|
4
|
-
class ObjectHavingAttributes <
|
4
|
+
class ObjectHavingAttributes < Basic::OperationTreeBuilders::DefaultObject
|
5
5
|
def self.applies_to?(expected, _actual)
|
6
6
|
SuperDiff::RSpec.an_object_having_some_attributes?(expected)
|
7
7
|
end
|
@@ -9,7 +9,7 @@ module SuperDiff
|
|
9
9
|
protected
|
10
10
|
|
11
11
|
def build_operation_tree
|
12
|
-
find_operation_tree_for(actual)
|
12
|
+
SuperDiff.find_operation_tree_for(actual)
|
13
13
|
end
|
14
14
|
|
15
15
|
def attribute_names
|
data/lib/super_diff/rspec.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require "super_diff"
|
2
2
|
|
3
|
+
require "super_diff/rspec/differs"
|
4
|
+
require "super_diff/rspec/inspection_tree_builders"
|
5
|
+
require "super_diff/rspec/operation_tree_builders"
|
6
|
+
|
3
7
|
module SuperDiff
|
4
8
|
module RSpec
|
5
9
|
autoload :AugmentedMatcher, "super_diff/rspec/augmented_matcher"
|
6
10
|
autoload :Configuration, "super_diff/rspec/configuration"
|
7
11
|
autoload :Differ, "super_diff/rspec/differ"
|
8
|
-
autoload :Differs, "super_diff/rspec/differs"
|
9
12
|
autoload :MatcherTextBuilders, "super_diff/rspec/matcher_text_builders"
|
10
13
|
autoload :MatcherTextTemplate, "super_diff/rspec/matcher_text_template"
|
11
14
|
autoload :ObjectInspection, "super_diff/rspec/object_inspection"
|
12
|
-
autoload :OperationTreeBuilders, "super_diff/rspec/operation_tree_builders"
|
13
15
|
|
14
16
|
def self.configure(&block)
|
15
17
|
SuperDiff.configure(&block)
|
@@ -20,7 +22,7 @@ module SuperDiff
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.a_hash_including_something?(value)
|
23
|
-
|
25
|
+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
|
24
26
|
value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
|
25
27
|
end
|
26
28
|
|
@@ -31,7 +33,7 @@ module SuperDiff
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.a_collection_including_something?(value)
|
34
|
-
|
36
|
+
aliased_matcher?(value) && value.respond_to?(:expecteds) &&
|
35
37
|
!(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
|
36
38
|
end
|
37
39
|
|
@@ -40,17 +42,17 @@ module SuperDiff
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def self.an_object_having_some_attributes?(value)
|
43
|
-
|
45
|
+
aliased_matcher?(value) &&
|
44
46
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::HaveAttributes)
|
45
47
|
end
|
46
48
|
|
47
49
|
def self.a_collection_containing_exactly_something?(value)
|
48
|
-
|
50
|
+
aliased_matcher?(value) &&
|
49
51
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::ContainExactly)
|
50
52
|
end
|
51
53
|
|
52
54
|
def self.a_kind_of_something?(value)
|
53
|
-
|
55
|
+
aliased_matcher?(value) &&
|
54
56
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAKindOf)
|
55
57
|
end
|
56
58
|
|
@@ -61,7 +63,7 @@ module SuperDiff
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def self.an_instance_of_something?(value)
|
64
|
-
|
66
|
+
aliased_matcher?(value) &&
|
65
67
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
|
66
68
|
end
|
67
69
|
|
@@ -72,11 +74,11 @@ module SuperDiff
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def self.a_value_within_something?(value)
|
75
|
-
|
77
|
+
aliased_matcher?(value) &&
|
76
78
|
value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
|
77
79
|
end
|
78
80
|
|
79
|
-
def self.
|
81
|
+
def self.aliased_matcher?(value)
|
80
82
|
value.is_a?(::RSpec::Matchers::AliasedMatcher)
|
81
83
|
end
|
82
84
|
|
@@ -84,36 +86,37 @@ module SuperDiff
|
|
84
86
|
@_rspec_version ||=
|
85
87
|
begin
|
86
88
|
require "rspec/core/version"
|
87
|
-
GemVersion.new(::RSpec::Core::Version::STRING)
|
89
|
+
Core::GemVersion.new(::RSpec::Core::Version::STRING)
|
88
90
|
end
|
89
91
|
end
|
90
92
|
|
91
93
|
SuperDiff.configuration.tap do |config|
|
92
|
-
config.
|
94
|
+
config.prepend_extra_differ_classes(
|
93
95
|
Differs::CollectionContainingExactly,
|
94
96
|
Differs::CollectionIncluding,
|
95
97
|
Differs::HashIncluding,
|
96
98
|
Differs::ObjectHavingAttributes
|
97
99
|
)
|
98
100
|
|
99
|
-
config.
|
101
|
+
config.prepend_extra_inspection_tree_builder_classes(
|
102
|
+
InspectionTreeBuilders::Double,
|
103
|
+
InspectionTreeBuilders::CollectionContainingExactly,
|
104
|
+
InspectionTreeBuilders::CollectionIncluding,
|
105
|
+
InspectionTreeBuilders::HashIncluding,
|
106
|
+
InspectionTreeBuilders::InstanceOf,
|
107
|
+
InspectionTreeBuilders::KindOf,
|
108
|
+
InspectionTreeBuilders::ObjectHavingAttributes,
|
109
|
+
# ObjectInspection::InspectionTreeBuilders::Primitive,
|
110
|
+
InspectionTreeBuilders::ValueWithin,
|
111
|
+
InspectionTreeBuilders::GenericDescribableMatcher
|
112
|
+
)
|
113
|
+
|
114
|
+
config.prepend_extra_operation_tree_builder_classes(
|
100
115
|
OperationTreeBuilders::CollectionContainingExactly,
|
101
116
|
OperationTreeBuilders::CollectionIncluding,
|
102
117
|
OperationTreeBuilders::HashIncluding,
|
103
118
|
OperationTreeBuilders::ObjectHavingAttributes
|
104
119
|
)
|
105
|
-
|
106
|
-
config.add_extra_inspection_tree_builder_classes(
|
107
|
-
ObjectInspection::InspectionTreeBuilders::Double,
|
108
|
-
ObjectInspection::InspectionTreeBuilders::CollectionContainingExactly,
|
109
|
-
ObjectInspection::InspectionTreeBuilders::CollectionIncluding,
|
110
|
-
ObjectInspection::InspectionTreeBuilders::HashIncluding,
|
111
|
-
ObjectInspection::InspectionTreeBuilders::InstanceOf,
|
112
|
-
ObjectInspection::InspectionTreeBuilders::KindOf,
|
113
|
-
ObjectInspection::InspectionTreeBuilders::ObjectHavingAttributes,
|
114
|
-
# ObjectInspection::InspectionTreeBuilders::Primitive,
|
115
|
-
ObjectInspection::InspectionTreeBuilders::ValueWithin
|
116
|
-
)
|
117
120
|
end
|
118
121
|
end
|
119
122
|
end
|
data/lib/super_diff/version.rb
CHANGED