super_diff 0.5.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +46 -20
- data/lib/super_diff.rb +46 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_model.rb +19 -20
- data/lib/super_diff/active_record/object_inspection/{inspectors → inspection_tree_builders}/active_record_relation.rb +9 -8
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb +17 -0
- data/lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +102 -19
- data/lib/super_diff/csi.rb +1 -1
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/diff_formatters/collection.rb +2 -2
- data/lib/super_diff/diff_formatters/multiline_string.rb +4 -4
- data/lib/super_diff/differs/array.rb +1 -1
- data/lib/super_diff/differs/base.rb +3 -21
- data/lib/super_diff/differs/custom_object.rb +1 -1
- data/lib/super_diff/differs/default_object.rb +1 -1
- data/lib/super_diff/differs/hash.rb +1 -1
- data/lib/super_diff/differs/main.rb +1 -7
- data/lib/super_diff/differs/multiline_string.rb +1 -1
- data/lib/super_diff/differs/time_like.rb +1 -1
- data/lib/super_diff/equality_matchers/array.rb +4 -4
- data/lib/super_diff/equality_matchers/default.rb +4 -4
- data/lib/super_diff/equality_matchers/hash.rb +4 -4
- data/lib/super_diff/equality_matchers/multiline_string.rb +4 -4
- data/lib/super_diff/equality_matchers/primitive.rb +6 -9
- data/lib/super_diff/equality_matchers/singleline_string.rb +4 -4
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/helpers.rb +52 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection.rb +12 -9
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- data/lib/super_diff/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +38 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/base.rb +27 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +37 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +63 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/defaults.rb +1 -2
- data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +46 -0
- data/lib/super_diff/object_inspection/{inspectors → inspection_tree_builders}/main.rb +5 -10
- data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +21 -0
- data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +64 -0
- data/lib/super_diff/object_inspection/nodes.rb +33 -32
- data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +97 -0
- data/lib/super_diff/object_inspection/nodes/as_prefix_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_prelude_when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/as_single_line.rb +33 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +55 -20
- data/lib/super_diff/object_inspection/nodes/inspection.rb +47 -7
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -5
- data/lib/super_diff/object_inspection/nodes/only_when.rb +54 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +16 -2
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +21 -6
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +20 -5
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_lines.rb +27 -0
- data/lib/super_diff/object_inspection/nodes/when_rendering_to_string.rb +27 -0
- data/lib/super_diff/object_inspection/prefix_for_next_node.rb +6 -0
- data/lib/super_diff/object_inspection/prelude_for_next_node.rb +6 -0
- data/lib/super_diff/operation_tree_builders/array.rb +7 -10
- data/lib/super_diff/operation_tree_builders/base.rb +6 -6
- data/lib/super_diff/operation_tree_builders/custom_object.rb +5 -2
- data/lib/super_diff/operation_tree_builders/default_object.rb +1 -1
- data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
- data/lib/super_diff/operation_tree_builders/hash.rb +1 -8
- data/lib/super_diff/operation_tree_builders/multiline_string.rb +2 -6
- data/lib/super_diff/operation_tree_builders/time_like.rb +2 -2
- data/lib/super_diff/operation_tree_flatteners.rb +20 -0
- data/lib/super_diff/operation_tree_flatteners/array.rb +15 -0
- data/lib/super_diff/operation_tree_flatteners/base.rb +54 -0
- data/lib/super_diff/operation_tree_flatteners/collection.rb +139 -0
- data/lib/super_diff/operation_tree_flatteners/custom_object.rb +28 -0
- data/lib/super_diff/operation_tree_flatteners/default_object.rb +32 -0
- data/lib/super_diff/operation_tree_flatteners/hash.rb +41 -0
- data/lib/super_diff/operation_tree_flatteners/multiline_string.rb +17 -0
- data/lib/super_diff/operation_trees/array.rb +4 -7
- data/lib/super_diff/operation_trees/base.rb +39 -16
- data/lib/super_diff/operation_trees/custom_object.rb +4 -8
- data/lib/super_diff/operation_trees/default_object.rb +28 -13
- data/lib/super_diff/operation_trees/hash.rb +4 -7
- data/lib/super_diff/operation_trees/main.rb +1 -1
- data/lib/super_diff/operation_trees/multiline_string.rb +4 -7
- data/lib/super_diff/operations/binary_operation.rb +1 -6
- data/lib/super_diff/operations/unary_operation.rb +2 -30
- data/lib/super_diff/recursion_guard.rb +3 -3
- data/lib/super_diff/rspec.rb +41 -13
- data/lib/super_diff/rspec/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +7 -7
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +4 -4
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +5 -5
- data/lib/super_diff/rspec/monkey_patches.rb +353 -306
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/collection_containing_exactly.rb +9 -8
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +34 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +103 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +36 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +26 -0
- data/lib/super_diff/rspec/object_inspection/{inspectors → inspection_tree_builders}/object_having_attributes.rb +10 -12
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/primitive.rb +10 -0
- data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +33 -0
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +12 -4
- data/lib/super_diff/rspec/operation_tree_builders/collection_including.rb +10 -3
- data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +10 -3
- data/lib/super_diff/tiered_lines.rb +4 -0
- data/lib/super_diff/tiered_lines_elider.rb +490 -0
- data/lib/super_diff/tiered_lines_formatter.rb +79 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +407 -5
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_matcher_spec.rb +100 -100
- data/spec/integration/rspec/be_nil_matcher_spec.rb +10 -10
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +103 -103
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +10 -10
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +113 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +223 -277
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +138 -129
- data/spec/integration/rspec/have_predicate_matcher_spec.rb +65 -65
- data/spec/integration/rspec/include_matcher_spec.rb +73 -73
- data/spec/integration/rspec/match_array_matcher_spec.rb +126 -119
- data/spec/integration/rspec/match_matcher_spec.rb +362 -274
- data/spec/integration/rspec/raise_error_matcher_spec.rb +86 -86
- data/spec/integration/rspec/respond_to_matcher_spec.rb +240 -240
- data/spec/integration/rspec/third_party_matcher_spec.rb +8 -8
- data/spec/integration/rspec/unhandled_errors_spec.rb +5 -5
- data/spec/spec_helper.rb +33 -13
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +8 -2
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +4 -4
- data/spec/support/integration/test_programs/base.rb +38 -10
- data/spec/support/integration/test_programs/rspec_active_record.rb +1 -1
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +1 -1
- data/spec/support/shared_examples/active_record.rb +109 -108
- data/spec/support/shared_examples/active_support.rb +65 -0
- data/spec/support/shared_examples/elided_diffs.rb +914 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +445 -465
- data/spec/unit/helpers_spec.rb +61 -0
- data/spec/unit/operation_tree_flatteners/array_spec.rb +604 -0
- data/spec/unit/operation_tree_flatteners/custom_object_spec.rb +667 -0
- data/spec/unit/operation_tree_flatteners/default_object_spec.rb +687 -0
- data/spec/unit/operation_tree_flatteners/hash_spec.rb +632 -0
- data/spec/unit/operation_tree_flatteners/multiline_string_spec.rb +121 -0
- data/spec/unit/rspec/object_inspection_spec.rb +446 -0
- data/spec/unit/super_diff_spec.rb +1958 -0
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- data/super_diff.gemspec +1 -1
- metadata +95 -50
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- data/lib/super_diff/diff_formatters.rb +0 -14
- data/lib/super_diff/diff_formatters/array.rb +0 -21
- data/lib/super_diff/diff_formatters/base.rb +0 -33
- data/lib/super_diff/diff_formatters/custom_object.rb +0 -30
- data/lib/super_diff/diff_formatters/default_object.rb +0 -46
- data/lib/super_diff/diff_formatters/defaults.rb +0 -10
- data/lib/super_diff/diff_formatters/hash.rb +0 -34
- data/lib/super_diff/diff_formatters/main.rb +0 -41
- data/lib/super_diff/object_inspection/inspectors.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/array.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/base.rb +0 -36
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +0 -37
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +0 -61
- data/lib/super_diff/object_inspection/inspectors/hash.rb +0 -32
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +0 -28
- data/lib/super_diff/object_inspection/inspectors/string.rb +0 -23
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +0 -23
- data/lib/super_diff/object_inspection/nodes/break.rb +0 -15
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +0 -22
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +0 -24
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +0 -28
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +0 -23
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +0 -13
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +0 -29
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
- data/spec/unit/object_inspection_spec.rb +0 -1168
@@ -1,29 +0,0 @@
|
|
1
|
-
module SuperDiff
|
2
|
-
module RSpec
|
3
|
-
module ObjectInspection
|
4
|
-
module Inspectors
|
5
|
-
class ValueWithin < SuperDiff::ObjectInspection::Inspectors::Base
|
6
|
-
def self.applies_to?(value)
|
7
|
-
SuperDiff::RSpec.a_value_within_something?(value)
|
8
|
-
end
|
9
|
-
|
10
|
-
protected
|
11
|
-
|
12
|
-
def inspection_tree
|
13
|
-
SuperDiff::ObjectInspection::InspectionTree.new do
|
14
|
-
add_text "#<a value within "
|
15
|
-
|
16
|
-
add_inspection_of do |aliased_matcher|
|
17
|
-
aliased_matcher.base_matcher.instance_variable_get("@delta")
|
18
|
-
end
|
19
|
-
|
20
|
-
add_text " of "
|
21
|
-
add_inspection_of(&:expected)
|
22
|
-
add_text ">"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/support/object_id.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
require_relative "ruby_versions"
|
3
|
-
|
4
|
-
if !SuperDiff::Test.jruby? && SuperDiff::Test.version_match?(">= 2.7.0")
|
5
|
-
require "objspace"
|
6
|
-
end
|
7
|
-
|
8
|
-
module SuperDiff
|
9
|
-
module Test
|
10
|
-
if jruby?
|
11
|
-
def self.object_id_hex(object)
|
12
|
-
# Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
|
13
|
-
"0x%x" % object.hash
|
14
|
-
end
|
15
|
-
elsif version_match?(">= 2.7.0")
|
16
|
-
def self.object_id_hex(object)
|
17
|
-
# Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
|
18
|
-
address = JSON.parse(ObjectSpace.dump(object))["address"]
|
19
|
-
"0x%016x" % Integer(address, 16)
|
20
|
-
end
|
21
|
-
else
|
22
|
-
def self.object_id_hex(object)
|
23
|
-
"0x%016x" % (object.object_id * 2)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,1168 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe SuperDiff::ObjectInspection do
|
4
|
-
describe ".inspect" do
|
5
|
-
context "given nil" do
|
6
|
-
context "given as_single_line: true" do
|
7
|
-
it "returns nil, inspected" do
|
8
|
-
inspection = described_class.inspect(nil, as_single_line: true)
|
9
|
-
expect(inspection).to eq("nil")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "given as_single_line: false" do
|
14
|
-
it "returns nil, inspected" do
|
15
|
-
inspection = described_class.inspect(nil, as_single_line: false)
|
16
|
-
expect(inspection).to eq("nil")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "given true" do
|
22
|
-
context "given as_single_line: true" do
|
23
|
-
it "returns nil, inspected" do
|
24
|
-
inspection = described_class.inspect(nil, as_single_line: true)
|
25
|
-
expect(inspection).to eq("nil")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "given as_single_line: false" do
|
30
|
-
it "returns nil, inspected" do
|
31
|
-
inspection = described_class.inspect(nil, as_single_line: false)
|
32
|
-
expect(inspection).to eq("nil")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "given false" do
|
38
|
-
context "given as_single_line: false" do
|
39
|
-
it "returns false, inspected" do
|
40
|
-
inspection = described_class.inspect(false, as_single_line: false)
|
41
|
-
expect(inspection).to eq("false")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "given as_single_line: false" do
|
46
|
-
it "returns false, inspected" do
|
47
|
-
inspection = described_class.inspect(false, as_single_line: false)
|
48
|
-
expect(inspection).to eq("false")
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "given a number" do
|
54
|
-
context "given as_single_line: true" do
|
55
|
-
it "returns the number as a string" do
|
56
|
-
inspection = described_class.inspect(3, as_single_line: true)
|
57
|
-
expect(inspection).to eq("3")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "given as_single_line: false" do
|
62
|
-
it "returns the number as a string" do
|
63
|
-
inspection = described_class.inspect(3, as_single_line: false)
|
64
|
-
expect(inspection).to eq("3")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "given a symbol" do
|
70
|
-
context "given as_single_line: true" do
|
71
|
-
it "returns the symbol, inspected" do
|
72
|
-
inspection = described_class.inspect(:foo, as_single_line: true)
|
73
|
-
expect(inspection).to eq(":foo")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "given as_single_line: false" do
|
78
|
-
it "returns the symbol, inspected" do
|
79
|
-
inspection = described_class.inspect(:foo, as_single_line: false)
|
80
|
-
expect(inspection).to eq(":foo")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "given a regex" do
|
86
|
-
context "given as_single_line: true" do
|
87
|
-
it "returns the regex, inspected" do
|
88
|
-
inspection = described_class.inspect(/foo/, as_single_line: true)
|
89
|
-
expect(inspection).to eq("/foo/")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "given as_single_line: false" do
|
94
|
-
it "returns the regex, inspected" do
|
95
|
-
inspection = described_class.inspect(/foo/, as_single_line: false)
|
96
|
-
expect(inspection).to eq("/foo/")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "given a single-line string" do
|
102
|
-
it "returns the string surrounded by quotes" do
|
103
|
-
inspection = described_class.inspect("Marty", as_single_line: true)
|
104
|
-
expect(inspection).to eq('"Marty"')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "given a multi-line string" do
|
109
|
-
context "that does not contain color codes" do
|
110
|
-
it "returns the string surrounded by quotes, with newline characters escaped" do
|
111
|
-
inspection = described_class.inspect(
|
112
|
-
"This is a line\nAnd that's a line\nAnd there's a line too",
|
113
|
-
as_single_line: true,
|
114
|
-
)
|
115
|
-
expect(inspection).to eq(
|
116
|
-
%("This is a line\\nAnd that's a line\\nAnd there's a line too"),
|
117
|
-
)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "that contains color codes" do
|
122
|
-
it "escapes the color codes" do
|
123
|
-
colors = [
|
124
|
-
SuperDiff::Csi::FourBitColor.new(:blue, layer: :foreground),
|
125
|
-
SuperDiff::Csi::EightBitColor.new(
|
126
|
-
red: 3,
|
127
|
-
green: 8,
|
128
|
-
blue: 4,
|
129
|
-
layer: :foreground,
|
130
|
-
),
|
131
|
-
SuperDiff::Csi::TwentyFourBitColor.new(
|
132
|
-
red: 47,
|
133
|
-
green: 164,
|
134
|
-
blue: 59,
|
135
|
-
layer: :foreground,
|
136
|
-
),
|
137
|
-
]
|
138
|
-
string_to_inspect = [
|
139
|
-
colorize("This is a line", colors[0]),
|
140
|
-
colorize("And that's a line", colors[1]),
|
141
|
-
colorize("And there's a line too", colors[2]),
|
142
|
-
].join("\n")
|
143
|
-
|
144
|
-
inspection = described_class.inspect(
|
145
|
-
string_to_inspect,
|
146
|
-
as_single_line: true,
|
147
|
-
)
|
148
|
-
# TODO: Figure out how to represent a colorized string inside of an
|
149
|
-
# already colorized string
|
150
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
151
|
-
"\\e[34mThis is a line\\e[0m\\n\\e[38;5;176mAnd that's a line\\e[0m\\n\\e[38;2;47;59;164mAnd there's a line too\\e[0m"
|
152
|
-
INSPECTION
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "given an array" do
|
158
|
-
context "containing only primitive values" do
|
159
|
-
context "given as_single_line: true" do
|
160
|
-
it "returns a representation of the array on a single line" do
|
161
|
-
inspection = described_class.inspect(
|
162
|
-
["foo", 2, :baz],
|
163
|
-
as_single_line: true,
|
164
|
-
)
|
165
|
-
expect(inspection).to eq(%(["foo", 2, :baz]))
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "given as_single_line: false" do
|
170
|
-
it "returns a representation of the array across multiple lines" do
|
171
|
-
inspection = described_class.inspect(
|
172
|
-
["foo", 2, :baz],
|
173
|
-
as_single_line: false,
|
174
|
-
)
|
175
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
176
|
-
[
|
177
|
-
"foo",
|
178
|
-
2,
|
179
|
-
:baz
|
180
|
-
]
|
181
|
-
INSPECTION
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "containing other arrays" do
|
187
|
-
context "given as_single_line: true" do
|
188
|
-
it "returns a representation of the array on a single line" do
|
189
|
-
inspection = described_class.inspect(
|
190
|
-
[
|
191
|
-
"foo",
|
192
|
-
["bar", "baz"],
|
193
|
-
"qux",
|
194
|
-
],
|
195
|
-
as_single_line: true,
|
196
|
-
)
|
197
|
-
expect(inspection).to eq(%(["foo", ["bar", "baz"], "qux"]))
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
context "given as_single_line: false" do
|
202
|
-
it "returns a representation of the array across multiple lines" do
|
203
|
-
inspection = described_class.inspect(
|
204
|
-
[
|
205
|
-
"foo",
|
206
|
-
["bar", "baz"],
|
207
|
-
"qux",
|
208
|
-
],
|
209
|
-
as_single_line: false,
|
210
|
-
)
|
211
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
212
|
-
[
|
213
|
-
"foo",
|
214
|
-
[
|
215
|
-
"bar",
|
216
|
-
"baz"
|
217
|
-
],
|
218
|
-
"qux"
|
219
|
-
]
|
220
|
-
INSPECTION
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context "which is empty" do
|
226
|
-
context "given as_single_line: true" do
|
227
|
-
it "returns a representation of the array on a single line" do
|
228
|
-
inspection = described_class.inspect([], as_single_line: true)
|
229
|
-
expect(inspection).to eq(%([]))
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context "given as_single_line: false" do
|
234
|
-
it "returns a representation of the array on a single line" do
|
235
|
-
inspection = described_class.inspect([], as_single_line: false)
|
236
|
-
expect(inspection).to eq(%([]))
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
context "given a hash" do
|
243
|
-
context "containing only primitive values" do
|
244
|
-
context "where all of the keys are symbols" do
|
245
|
-
context "given as_single_line: true" do
|
246
|
-
it "returns a representation of the hash on a single line" do
|
247
|
-
inspection = described_class.inspect(
|
248
|
-
# rubocop:disable Style/HashSyntax
|
249
|
-
{ :foo => "bar", :baz => "qux" },
|
250
|
-
# rubocop:enable Style/HashSyntax
|
251
|
-
as_single_line: true,
|
252
|
-
)
|
253
|
-
expect(inspection).to eq(%({ foo: "bar", baz: "qux" }))
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
context "given as_single_line: false" do
|
258
|
-
it "returns a representation of the hash across multiple lines" do
|
259
|
-
inspection = described_class.inspect(
|
260
|
-
# rubocop:disable Style/HashSyntax
|
261
|
-
{ :foo => "bar", :baz => "qux" },
|
262
|
-
# rubocop:enable Style/HashSyntax
|
263
|
-
as_single_line: false,
|
264
|
-
)
|
265
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
266
|
-
{
|
267
|
-
foo: "bar",
|
268
|
-
baz: "qux"
|
269
|
-
}
|
270
|
-
INSPECTION
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context "where only some of the keys are symbols" do
|
276
|
-
context "given as_single_line: true" do
|
277
|
-
it "returns a representation of the hash on a single line" do
|
278
|
-
inspection = described_class.inspect(
|
279
|
-
{ :foo => "bar", 2 => "baz" },
|
280
|
-
as_single_line: true,
|
281
|
-
)
|
282
|
-
expect(inspection).to eq(%({ :foo => "bar", 2 => "baz" }))
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context "given as_single_line: false" do
|
287
|
-
it "returns a representation of the hash across multiple lines" do
|
288
|
-
inspection = described_class.inspect(
|
289
|
-
{ :foo => "bar", 2 => "baz" },
|
290
|
-
as_single_line: false,
|
291
|
-
)
|
292
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
293
|
-
{
|
294
|
-
:foo => "bar",
|
295
|
-
2 => "baz"
|
296
|
-
}
|
297
|
-
INSPECTION
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
context "containing other hashes" do
|
304
|
-
context "given as_single_line: true" do
|
305
|
-
it "returns a representation of the hash on a single line" do
|
306
|
-
# TODO: Update this with a key/value pair before AND after
|
307
|
-
value_to_inspect = {
|
308
|
-
# rubocop:disable Style/HashSyntax
|
309
|
-
:category_name => "Appliances",
|
310
|
-
:products_by_sku => {
|
311
|
-
"EMDL-2934" => { :id => 4, :name => "Jordan Air" },
|
312
|
-
"KDS-3912" => { :id => 8, :name => "Chevy Impala" },
|
313
|
-
},
|
314
|
-
:number_of_products => 2,
|
315
|
-
# rubocop:enable Style/HashSyntax
|
316
|
-
}
|
317
|
-
inspection = described_class.inspect(
|
318
|
-
value_to_inspect,
|
319
|
-
as_single_line: true,
|
320
|
-
)
|
321
|
-
# rubocop:disable Metrics/LineLength
|
322
|
-
expect(inspection).to eq(
|
323
|
-
%({ category_name: "Appliances", products_by_sku: { "EMDL-2934" => { id: 4, name: "Jordan Air" }, "KDS-3912" => { id: 8, name: "Chevy Impala" } }, number_of_products: 2 }),
|
324
|
-
)
|
325
|
-
# rubocop:enable Metrics/LineLength
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
context "given as_single_line: false" do
|
330
|
-
it "returns a representation of the array across multiple lines" do
|
331
|
-
value_to_inspect = {
|
332
|
-
# rubocop:disable Style/HashSyntax
|
333
|
-
:category_name => "Appliances",
|
334
|
-
:products_by_sku => {
|
335
|
-
"EMDL-2934" => { :id => 4, :name => "George Foreman Grill" },
|
336
|
-
"KDS-3912" => { :id => 8, :name => "Magic Bullet" },
|
337
|
-
},
|
338
|
-
:number_of_products => 2,
|
339
|
-
# rubocop:enable Style/HashSyntax
|
340
|
-
}
|
341
|
-
inspection = described_class.inspect(
|
342
|
-
value_to_inspect,
|
343
|
-
as_single_line: false,
|
344
|
-
)
|
345
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
346
|
-
{
|
347
|
-
category_name: "Appliances",
|
348
|
-
products_by_sku: {
|
349
|
-
"EMDL-2934" => {
|
350
|
-
id: 4,
|
351
|
-
name: "George Foreman Grill"
|
352
|
-
},
|
353
|
-
"KDS-3912" => {
|
354
|
-
id: 8,
|
355
|
-
name: "Magic Bullet"
|
356
|
-
}
|
357
|
-
},
|
358
|
-
number_of_products: 2
|
359
|
-
}
|
360
|
-
INSPECTION
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context "which is empty" do
|
366
|
-
context "given as_single_line: true" do
|
367
|
-
it "returns a representation of the array on a single line" do
|
368
|
-
inspection = described_class.inspect({}, as_single_line: true)
|
369
|
-
expect(inspection).to eq(%({}))
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
context "given as_single_line: false" do
|
374
|
-
it "returns a representation of the array on a single line" do
|
375
|
-
inspection = described_class.inspect({}, as_single_line: false)
|
376
|
-
expect(inspection).to eq(%({}))
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
context "given a class" do
|
383
|
-
context "given as_single_line: true" do
|
384
|
-
it "returns a representation of the object on a single line" do
|
385
|
-
inspection = described_class.inspect(
|
386
|
-
SuperDiff::Test::Person,
|
387
|
-
as_single_line: true,
|
388
|
-
)
|
389
|
-
expect(inspection).to eq("SuperDiff::Test::Person")
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
context "given as_single_line: false" do
|
394
|
-
it "returns a representation of the object on a single line" do
|
395
|
-
inspection = described_class.inspect(
|
396
|
-
SuperDiff::Test::Person,
|
397
|
-
as_single_line: false,
|
398
|
-
)
|
399
|
-
expect(inspection).to eq("SuperDiff::Test::Person")
|
400
|
-
end
|
401
|
-
end
|
402
|
-
end
|
403
|
-
|
404
|
-
context "given a custom object" do
|
405
|
-
context "containing only primitive values" do
|
406
|
-
context "given as_single_line: true" do
|
407
|
-
it "returns a representation of the object on a single line" do
|
408
|
-
inspection = described_class.inspect(
|
409
|
-
SuperDiff::Test::Person.new(name: "Doc", age: 58),
|
410
|
-
as_single_line: true,
|
411
|
-
)
|
412
|
-
expect(inspection).to eq(
|
413
|
-
%(#<SuperDiff::Test::Person name: "Doc", age: 58>),
|
414
|
-
)
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
context "given as_single_line: false" do
|
419
|
-
it "returns a representation of the object across multiple lines" do
|
420
|
-
inspection = described_class.inspect(
|
421
|
-
SuperDiff::Test::Person.new(name: "Doc", age: 58),
|
422
|
-
as_single_line: false,
|
423
|
-
)
|
424
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
425
|
-
#<SuperDiff::Test::Person {
|
426
|
-
name: "Doc",
|
427
|
-
age: 58
|
428
|
-
}>
|
429
|
-
INSPECTION
|
430
|
-
end
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
context "containing other custom objects" do
|
435
|
-
context "given as_single_line: true" do
|
436
|
-
it "returns a representation of the object on a single line" do
|
437
|
-
inspection = described_class.inspect(
|
438
|
-
SuperDiff::Test::Customer.new(
|
439
|
-
name: "Marty McFly",
|
440
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
441
|
-
line_1: "123 Main St.",
|
442
|
-
line_2: "",
|
443
|
-
city: "Hill Valley",
|
444
|
-
state: "CA",
|
445
|
-
zip: "90382",
|
446
|
-
),
|
447
|
-
phone: "111-222-3333",
|
448
|
-
),
|
449
|
-
as_single_line: true,
|
450
|
-
)
|
451
|
-
expect(inspection).to eq(
|
452
|
-
# rubocop:disable Metrics/LineLength
|
453
|
-
%(#<SuperDiff::Test::Customer name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Main St.", line_2: "", city: "Hill Valley", state: "CA", zip: "90382">, phone: "111-222-3333">),
|
454
|
-
# rubocop:enable Metrics/LineLength
|
455
|
-
)
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
context "given as_single_line: false" do
|
460
|
-
it "returns a representation of the object across multiple lines" do
|
461
|
-
inspection = described_class.inspect(
|
462
|
-
SuperDiff::Test::Customer.new(
|
463
|
-
name: "Marty McFly",
|
464
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
465
|
-
line_1: "123 Main St.",
|
466
|
-
line_2: "",
|
467
|
-
city: "Hill Valley",
|
468
|
-
state: "CA",
|
469
|
-
zip: "90382",
|
470
|
-
),
|
471
|
-
phone: "111-222-3333",
|
472
|
-
),
|
473
|
-
as_single_line: false,
|
474
|
-
)
|
475
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
476
|
-
#<SuperDiff::Test::Customer {
|
477
|
-
name: "Marty McFly",
|
478
|
-
shipping_address: #<SuperDiff::Test::ShippingAddress {
|
479
|
-
line_1: "123 Main St.",
|
480
|
-
line_2: "",
|
481
|
-
city: "Hill Valley",
|
482
|
-
state: "CA",
|
483
|
-
zip: "90382"
|
484
|
-
}>,
|
485
|
-
phone: "111-222-3333"
|
486
|
-
}>
|
487
|
-
INSPECTION
|
488
|
-
end
|
489
|
-
end
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
context "given a non-custom object" do
|
494
|
-
context "containing only primitive values" do
|
495
|
-
context "given as_single_line: true" do
|
496
|
-
it "returns a representation of the object on a single line" do
|
497
|
-
inspection = described_class.inspect(
|
498
|
-
SuperDiff::Test::Item.new(
|
499
|
-
name: "mac and cheese",
|
500
|
-
quantity: 2,
|
501
|
-
),
|
502
|
-
as_single_line: true,
|
503
|
-
)
|
504
|
-
expect(inspection).to match(
|
505
|
-
# rubocop:disable Metrics/LineLength
|
506
|
-
/\A#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="mac and cheese", @quantity=2>\Z/,
|
507
|
-
# rubocop:enable Metrics/LineLength
|
508
|
-
)
|
509
|
-
end
|
510
|
-
end
|
511
|
-
|
512
|
-
context "given as_single_line: false" do
|
513
|
-
it "returns a representation of the object across multiple lines" do
|
514
|
-
inspection = described_class.inspect(
|
515
|
-
SuperDiff::Test::Item.new(
|
516
|
-
name: "mac and cheese",
|
517
|
-
quantity: 2,
|
518
|
-
),
|
519
|
-
as_single_line: false,
|
520
|
-
)
|
521
|
-
regexp = <<~INSPECTION.rstrip
|
522
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
523
|
-
@name="mac and cheese",
|
524
|
-
@quantity=2
|
525
|
-
\\}>
|
526
|
-
INSPECTION
|
527
|
-
expect(inspection).to match(/\A#{regexp}\Z/)
|
528
|
-
end
|
529
|
-
end
|
530
|
-
end
|
531
|
-
|
532
|
-
context "containing other custom objects" do
|
533
|
-
context "given as_single_line: true" do
|
534
|
-
it "returns a representation of the object on a single line" do
|
535
|
-
inspection = described_class.inspect(
|
536
|
-
SuperDiff::Test::Order.new([
|
537
|
-
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
538
|
-
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
539
|
-
SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
|
540
|
-
]),
|
541
|
-
as_single_line: true,
|
542
|
-
)
|
543
|
-
expect(inspection).to match(
|
544
|
-
# rubocop:disable Metrics/LineLength
|
545
|
-
/\A#<SuperDiff::Test::Order:0x[a-z0-9]+ @items=\[#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="ham", @quantity=1>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="eggs", @quantity=2>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="cheese", @quantity=1>\]>\Z/,
|
546
|
-
# rubocop:enable Metrics/LineLength
|
547
|
-
)
|
548
|
-
end
|
549
|
-
end
|
550
|
-
|
551
|
-
context "given as_single_line: false" do
|
552
|
-
it "returns a representation of the object across multiple lines" do
|
553
|
-
inspection = described_class.inspect(
|
554
|
-
SuperDiff::Test::Order.new([
|
555
|
-
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
556
|
-
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
557
|
-
SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
|
558
|
-
]),
|
559
|
-
as_single_line: false,
|
560
|
-
)
|
561
|
-
regexp = <<~INSPECTION.rstrip
|
562
|
-
#<SuperDiff::Test::Order:0x[a-z0-9]+ \\{
|
563
|
-
@items=\\[
|
564
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
565
|
-
@name="ham",
|
566
|
-
@quantity=1
|
567
|
-
\\}>,
|
568
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
569
|
-
@name="eggs",
|
570
|
-
@quantity=2
|
571
|
-
\\}>,
|
572
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
573
|
-
@name="cheese",
|
574
|
-
@quantity=1
|
575
|
-
\\}>
|
576
|
-
\\]
|
577
|
-
}>
|
578
|
-
INSPECTION
|
579
|
-
expect(inspection).to match(/\A#{regexp}\Z/)
|
580
|
-
end
|
581
|
-
end
|
582
|
-
end
|
583
|
-
|
584
|
-
context "which is empty" do
|
585
|
-
context "given as_single_line: true" do
|
586
|
-
it "returns a representation of the array on a single line" do
|
587
|
-
inspection = described_class.inspect(
|
588
|
-
SuperDiff::Test::EmptyClass.new,
|
589
|
-
as_single_line: true,
|
590
|
-
)
|
591
|
-
expect(inspection).to match(
|
592
|
-
/#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/
|
593
|
-
)
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
context "given as_single_line: false" do
|
598
|
-
it "returns a representation of the array on a single line" do
|
599
|
-
inspection = described_class.inspect(
|
600
|
-
SuperDiff::Test::EmptyClass.new,
|
601
|
-
as_single_line: false,
|
602
|
-
)
|
603
|
-
expect(inspection).to match(
|
604
|
-
/#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
|
605
|
-
)
|
606
|
-
end
|
607
|
-
end
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
context "given a hash-including-<something>" do
|
612
|
-
context "given as_single_line: true" do
|
613
|
-
it "returns a representation of the object on a single line" do
|
614
|
-
inspection = described_class.inspect(
|
615
|
-
a_hash_including(foo: "bar", baz: "qux"),
|
616
|
-
as_single_line: true,
|
617
|
-
)
|
618
|
-
|
619
|
-
expect(inspection).to eq(
|
620
|
-
%(#<a hash including (foo: "bar", baz: "qux")>),
|
621
|
-
)
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
context "given as_single_line: false" do
|
626
|
-
it "returns a representation of the object across multiple lines" do
|
627
|
-
inspection = described_class.inspect(
|
628
|
-
a_hash_including(foo: "bar", baz: "qux"),
|
629
|
-
as_single_line: false,
|
630
|
-
)
|
631
|
-
|
632
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
633
|
-
#<a hash including (
|
634
|
-
foo: "bar",
|
635
|
-
baz: "qux"
|
636
|
-
)>
|
637
|
-
INSPECTION
|
638
|
-
end
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
context "given a collection-including-<something>" do
|
643
|
-
context "given as_single_line: true" do
|
644
|
-
it "returns a representation of the object on a single line" do
|
645
|
-
inspection = described_class.inspect(
|
646
|
-
a_collection_including(1, 2, 3),
|
647
|
-
as_single_line: true,
|
648
|
-
)
|
649
|
-
|
650
|
-
expect(inspection).to eq(
|
651
|
-
%(#<a collection including (1, 2, 3)>),
|
652
|
-
)
|
653
|
-
end
|
654
|
-
end
|
655
|
-
|
656
|
-
context "given as_single_line: false" do
|
657
|
-
it "returns a representation of the object across multiple lines" do
|
658
|
-
inspection = described_class.inspect(
|
659
|
-
a_collection_including(1, 2, 3),
|
660
|
-
as_single_line: false,
|
661
|
-
)
|
662
|
-
|
663
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
664
|
-
#<a collection including (
|
665
|
-
1,
|
666
|
-
2,
|
667
|
-
3
|
668
|
-
)>
|
669
|
-
INSPECTION
|
670
|
-
end
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
context "given a fuzzy object" do
|
675
|
-
context "given as_single_line: true" do
|
676
|
-
it "returns a representation of the object on a single line" do
|
677
|
-
inspection = described_class.inspect(
|
678
|
-
an_object_having_attributes(foo: "bar", baz: "qux"),
|
679
|
-
as_single_line: true,
|
680
|
-
)
|
681
|
-
|
682
|
-
expect(inspection).to eq(
|
683
|
-
%(#<an object having attributes (foo: "bar", baz: "qux")>),
|
684
|
-
)
|
685
|
-
end
|
686
|
-
end
|
687
|
-
|
688
|
-
context "given as_single_line: false" do
|
689
|
-
it "returns a representation of the object across multiple lines" do
|
690
|
-
inspection = described_class.inspect(
|
691
|
-
an_object_having_attributes(foo: "bar", baz: "qux"),
|
692
|
-
as_single_line: false,
|
693
|
-
)
|
694
|
-
|
695
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
696
|
-
#<an object having attributes (
|
697
|
-
foo: "bar",
|
698
|
-
baz: "qux"
|
699
|
-
)>
|
700
|
-
INSPECTION
|
701
|
-
end
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
context "given a collection-containing-exactly-<something>" do
|
706
|
-
context "given as_single_line: true" do
|
707
|
-
it "returns a representation of the object on a single line" do
|
708
|
-
inspection = described_class.inspect(
|
709
|
-
a_collection_containing_exactly("foo", "bar", "baz"),
|
710
|
-
as_single_line: true,
|
711
|
-
)
|
712
|
-
|
713
|
-
expect(inspection).to eq(
|
714
|
-
%(#<a collection containing exactly ("foo", "bar", "baz")>),
|
715
|
-
)
|
716
|
-
end
|
717
|
-
end
|
718
|
-
|
719
|
-
context "given as_single_line: false" do
|
720
|
-
it "returns a representation of the object across multiple lines" do
|
721
|
-
inspection = described_class.inspect(
|
722
|
-
a_collection_containing_exactly("foo", "bar", "baz"),
|
723
|
-
as_single_line: false,
|
724
|
-
)
|
725
|
-
|
726
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
727
|
-
#<a collection containing exactly (
|
728
|
-
"foo",
|
729
|
-
"bar",
|
730
|
-
"baz"
|
731
|
-
)>
|
732
|
-
INSPECTION
|
733
|
-
end
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
context "given a kind-of-<something>" do
|
738
|
-
context "given as_single_line: true" do
|
739
|
-
it "returns a representation of the object on a single line" do
|
740
|
-
inspection = described_class.inspect(
|
741
|
-
a_kind_of(Symbol),
|
742
|
-
as_single_line: true,
|
743
|
-
)
|
744
|
-
|
745
|
-
expect(inspection).to eq(%(#<a kind of Symbol>))
|
746
|
-
end
|
747
|
-
end
|
748
|
-
|
749
|
-
context "given as_single_line: false" do
|
750
|
-
it "returns a representation of the object on a single line" do
|
751
|
-
inspection = described_class.inspect(
|
752
|
-
a_kind_of(Symbol),
|
753
|
-
as_single_line: false,
|
754
|
-
)
|
755
|
-
|
756
|
-
expect(inspection).to eq(%(#<a kind of Symbol>))
|
757
|
-
end
|
758
|
-
end
|
759
|
-
end
|
760
|
-
|
761
|
-
context "given an-instance-of-<something>" do
|
762
|
-
context "given as_single_line: true" do
|
763
|
-
it "returns a representation of the object on a single line" do
|
764
|
-
inspection = described_class.inspect(
|
765
|
-
an_instance_of(Symbol),
|
766
|
-
as_single_line: true,
|
767
|
-
)
|
768
|
-
|
769
|
-
expect(inspection).to eq(%(#<an instance of Symbol>))
|
770
|
-
end
|
771
|
-
end
|
772
|
-
|
773
|
-
context "given as_single_line: false" do
|
774
|
-
it "returns a representation of the object on a single line" do
|
775
|
-
inspection = described_class.inspect(
|
776
|
-
an_instance_of(Symbol),
|
777
|
-
as_single_line: false,
|
778
|
-
)
|
779
|
-
|
780
|
-
expect(inspection).to eq(%(#<an instance of Symbol>))
|
781
|
-
end
|
782
|
-
end
|
783
|
-
end
|
784
|
-
|
785
|
-
context "given a-value-within-<something>" do
|
786
|
-
context "given as_single_line: true" do
|
787
|
-
it "returns a representation of the object on a single line" do
|
788
|
-
inspection = described_class.inspect(
|
789
|
-
a_value_within(1).of(Time.utc(2020, 4, 9)),
|
790
|
-
as_single_line: true,
|
791
|
-
)
|
792
|
-
|
793
|
-
expect(inspection).to eq(
|
794
|
-
%(#<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>),
|
795
|
-
)
|
796
|
-
end
|
797
|
-
end
|
798
|
-
|
799
|
-
context "given as_single_line: false" do
|
800
|
-
it "returns a representation of the object on a single line" do
|
801
|
-
inspection = described_class.inspect(
|
802
|
-
a_value_within(1).of(Time.utc(2020, 4, 9)),
|
803
|
-
as_single_line: false,
|
804
|
-
)
|
805
|
-
|
806
|
-
expect(inspection).to eq(
|
807
|
-
%(#<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>),
|
808
|
-
)
|
809
|
-
end
|
810
|
-
end
|
811
|
-
end
|
812
|
-
|
813
|
-
context "given a Double" do
|
814
|
-
context "that is anonymous" do
|
815
|
-
context "given as_single_line: true" do
|
816
|
-
it "returns a representation of the object on a single line" do
|
817
|
-
inspection = described_class.inspect(
|
818
|
-
double(foo: "bar", baz: "qux"),
|
819
|
-
as_single_line: true,
|
820
|
-
)
|
821
|
-
|
822
|
-
expect(inspection).to eq("#<Double (anonymous)>")
|
823
|
-
end
|
824
|
-
end
|
825
|
-
|
826
|
-
context "given as_single_line: false" do
|
827
|
-
it "returns a representation of the object across multiple lines" do
|
828
|
-
inspection = described_class.inspect(
|
829
|
-
double(foo: "bar", baz: "qux"),
|
830
|
-
as_single_line: false,
|
831
|
-
)
|
832
|
-
|
833
|
-
expect(inspection).to eq("#<Double (anonymous)>")
|
834
|
-
end
|
835
|
-
end
|
836
|
-
end
|
837
|
-
end
|
838
|
-
|
839
|
-
context "given an ActiveRecord object", active_record: true do
|
840
|
-
context "given as_single_line: true" do
|
841
|
-
it "returns a representation of the object on a single line" do
|
842
|
-
inspection = described_class.inspect(
|
843
|
-
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
844
|
-
name: "Elliot",
|
845
|
-
age: 31,
|
846
|
-
),
|
847
|
-
as_single_line: true,
|
848
|
-
)
|
849
|
-
|
850
|
-
expect(inspection).to eq(
|
851
|
-
%(#<SuperDiff::Test::Models::ActiveRecord::Person id: nil, age: 31, name: "Elliot">)
|
852
|
-
)
|
853
|
-
end
|
854
|
-
end
|
855
|
-
|
856
|
-
context "given as_single_line: false" do
|
857
|
-
it "returns a representation of the object across multiple lines" do
|
858
|
-
inspection = described_class.inspect(
|
859
|
-
SuperDiff::Test::Models::ActiveRecord::Person.new(
|
860
|
-
name: "Elliot",
|
861
|
-
age: 31,
|
862
|
-
),
|
863
|
-
as_single_line: false,
|
864
|
-
)
|
865
|
-
|
866
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
867
|
-
#<SuperDiff::Test::Models::ActiveRecord::Person {
|
868
|
-
id: nil,
|
869
|
-
age: 31,
|
870
|
-
name: "Elliot"
|
871
|
-
}>
|
872
|
-
INSPECTION
|
873
|
-
end
|
874
|
-
end
|
875
|
-
end
|
876
|
-
|
877
|
-
context "given an ActiveRecord::Relation object", active_record: true do
|
878
|
-
context "given as_single_line: true" do
|
879
|
-
it "returns a representation of the Relation on a single line" do
|
880
|
-
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
881
|
-
name: "Marty",
|
882
|
-
age: 19,
|
883
|
-
)
|
884
|
-
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
885
|
-
name: "Jennifer",
|
886
|
-
age: 17,
|
887
|
-
)
|
888
|
-
|
889
|
-
inspection = described_class.inspect(
|
890
|
-
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
891
|
-
as_single_line: true,
|
892
|
-
)
|
893
|
-
|
894
|
-
expect(inspection).to eq(
|
895
|
-
%(#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 19, name: "Marty">, #<SuperDiff::Test::Models::ActiveRecord::Person id: 2, age: 17, name: "Jennifer">]>)
|
896
|
-
)
|
897
|
-
end
|
898
|
-
end
|
899
|
-
|
900
|
-
context "given as_single_line: false" do
|
901
|
-
it "returns a representation of the Relation across multiple lines" do
|
902
|
-
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
903
|
-
name: "Marty",
|
904
|
-
age: 19,
|
905
|
-
)
|
906
|
-
SuperDiff::Test::Models::ActiveRecord::Person.create!(
|
907
|
-
name: "Jennifer",
|
908
|
-
age: 17,
|
909
|
-
)
|
910
|
-
|
911
|
-
inspection = described_class.inspect(
|
912
|
-
SuperDiff::Test::Models::ActiveRecord::Person.all,
|
913
|
-
as_single_line: false,
|
914
|
-
)
|
915
|
-
|
916
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
917
|
-
#<ActiveRecord::Relation [
|
918
|
-
#<SuperDiff::Test::Models::ActiveRecord::Person {
|
919
|
-
id: 1,
|
920
|
-
age: 19,
|
921
|
-
name: "Marty"
|
922
|
-
}>,
|
923
|
-
#<SuperDiff::Test::Models::ActiveRecord::Person {
|
924
|
-
id: 2,
|
925
|
-
age: 17,
|
926
|
-
name: "Jennifer"
|
927
|
-
}>
|
928
|
-
]>
|
929
|
-
INSPECTION
|
930
|
-
end
|
931
|
-
end
|
932
|
-
end
|
933
|
-
|
934
|
-
context "given a HashWithIndifferentAccess", active_record: true do
|
935
|
-
context "given as_single_line: true" do
|
936
|
-
it "returns a representation of the object on a single line" do
|
937
|
-
inspection = described_class.inspect(
|
938
|
-
HashWithIndifferentAccess.new({
|
939
|
-
line_1: "123 Main St.",
|
940
|
-
city: "Hill Valley",
|
941
|
-
state: "CA",
|
942
|
-
zip: "90382",
|
943
|
-
}),
|
944
|
-
as_single_line: true,
|
945
|
-
)
|
946
|
-
|
947
|
-
expect(inspection).to eq(
|
948
|
-
%(#<HashWithIndifferentAccess { "line_1" => "123 Main St.", "city" => "Hill Valley", "state" => "CA", "zip" => "90382" }>)
|
949
|
-
)
|
950
|
-
end
|
951
|
-
end
|
952
|
-
|
953
|
-
context "given as_single_line: false" do
|
954
|
-
it "returns a representation of the object across multiple lines" do
|
955
|
-
inspection = described_class.inspect(
|
956
|
-
HashWithIndifferentAccess.new({
|
957
|
-
line_1: "123 Main St.",
|
958
|
-
city: "Hill Valley",
|
959
|
-
state: "CA",
|
960
|
-
zip: "90382",
|
961
|
-
}),
|
962
|
-
as_single_line: false,
|
963
|
-
)
|
964
|
-
|
965
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
966
|
-
#<HashWithIndifferentAccess {
|
967
|
-
"line_1" => "123 Main St.",
|
968
|
-
"city" => "Hill Valley",
|
969
|
-
"state" => "CA",
|
970
|
-
"zip" => "90382"
|
971
|
-
}>
|
972
|
-
INSPECTION
|
973
|
-
end
|
974
|
-
end
|
975
|
-
end
|
976
|
-
|
977
|
-
context "given a combination of all kinds of values" do
|
978
|
-
context "given as_single_line: true" do
|
979
|
-
it "returns a representation of the object on a single line" do
|
980
|
-
inspection = described_class.inspect(
|
981
|
-
{
|
982
|
-
state: :down,
|
983
|
-
errors: [
|
984
|
-
"Container A-234 is partially damaged",
|
985
|
-
"Vessel B042 was attacked by raccoons",
|
986
|
-
"Product FDK-3429 is out of stock",
|
987
|
-
],
|
988
|
-
mission_critical: true,
|
989
|
-
serviceable: false,
|
990
|
-
outstanding_orders: [
|
991
|
-
SuperDiff::Test::Order.new([
|
992
|
-
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
993
|
-
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
994
|
-
SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
|
995
|
-
]),
|
996
|
-
],
|
997
|
-
customers: [
|
998
|
-
SuperDiff::Test::Customer.new(
|
999
|
-
name: "Marty McFly",
|
1000
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
1001
|
-
line_1: "123 Baltic Ave.",
|
1002
|
-
line_2: "",
|
1003
|
-
city: "Hill Valley",
|
1004
|
-
state: "CA",
|
1005
|
-
zip: "90382",
|
1006
|
-
),
|
1007
|
-
phone: "111-111-1111",
|
1008
|
-
),
|
1009
|
-
SuperDiff::Test::Customer.new(
|
1010
|
-
name: "Doc Brown",
|
1011
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
1012
|
-
line_1: "456 Park Place",
|
1013
|
-
line_2: "",
|
1014
|
-
city: "Beverly Hills",
|
1015
|
-
state: "CA",
|
1016
|
-
zip: "90210",
|
1017
|
-
),
|
1018
|
-
phone: "222-222-2222",
|
1019
|
-
),
|
1020
|
-
],
|
1021
|
-
},
|
1022
|
-
as_single_line: true,
|
1023
|
-
)
|
1024
|
-
expect(inspection).to match(
|
1025
|
-
# rubocop:disable Metrics/LineLength
|
1026
|
-
/\A\{ state: :down, errors: \["Container A-234 is partially damaged", "Vessel B042 was attacked by raccoons", "Product FDK-3429 is out of stock"\], mission_critical: true, serviceable: false, outstanding_orders: \[#<SuperDiff::Test::Order:0x[a-z0-9]+ @items=\[#<SuperDiff::Test::Item:0x[a-z0-9]+ @name="ham", @quantity=1>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="eggs", @quantity=2>, #<SuperDiff::Test::Item:0x[a-z0-9]+ @name="cheese", @quantity=1>\]>\], customers: \[#<SuperDiff::Test::Customer name: "Marty McFly", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "123 Baltic Ave.", line_2: "", city: "Hill Valley", state: "CA", zip: "90382">, phone: "111-111-1111">, #<SuperDiff::Test::Customer name: "Doc Brown", shipping_address: #<SuperDiff::Test::ShippingAddress line_1: "456 Park Place", line_2: "", city: "Beverly Hills", state: "CA", zip: "90210">, phone: "222-222-2222">\] \}\Z/,
|
1027
|
-
# rubocop:enable Metrics/LineLength
|
1028
|
-
)
|
1029
|
-
end
|
1030
|
-
end
|
1031
|
-
|
1032
|
-
context "given as_single_line: false" do
|
1033
|
-
it "returns a representation of the object across multiple lines" do
|
1034
|
-
inspection = described_class.inspect(
|
1035
|
-
{
|
1036
|
-
state: :down,
|
1037
|
-
errors: [
|
1038
|
-
"Container A-234 is partially damaged",
|
1039
|
-
"Vessel B042 was attacked by raccoons",
|
1040
|
-
"Product FDK-3429 is out of stock",
|
1041
|
-
],
|
1042
|
-
mission_critical: true,
|
1043
|
-
serviceable: false,
|
1044
|
-
outstanding_orders: [
|
1045
|
-
SuperDiff::Test::Order.new([
|
1046
|
-
SuperDiff::Test::Item.new(name: "ham", quantity: 1),
|
1047
|
-
SuperDiff::Test::Item.new(name: "eggs", quantity: 2),
|
1048
|
-
SuperDiff::Test::Item.new(name: "cheese", quantity: 1),
|
1049
|
-
]),
|
1050
|
-
],
|
1051
|
-
customers: [
|
1052
|
-
SuperDiff::Test::Customer.new(
|
1053
|
-
name: "Marty McFly",
|
1054
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
1055
|
-
line_1: "123 Baltic Ave.",
|
1056
|
-
line_2: "",
|
1057
|
-
city: "Hill Valley",
|
1058
|
-
state: "CA",
|
1059
|
-
zip: "90382",
|
1060
|
-
),
|
1061
|
-
phone: "111-111-1111",
|
1062
|
-
),
|
1063
|
-
SuperDiff::Test::Customer.new(
|
1064
|
-
name: "Doc Brown",
|
1065
|
-
shipping_address: SuperDiff::Test::ShippingAddress.new(
|
1066
|
-
line_1: "456 Park Place",
|
1067
|
-
line_2: "",
|
1068
|
-
city: "Beverly Hills",
|
1069
|
-
state: "CA",
|
1070
|
-
zip: "90210",
|
1071
|
-
),
|
1072
|
-
phone: "222-222-2222",
|
1073
|
-
),
|
1074
|
-
],
|
1075
|
-
},
|
1076
|
-
as_single_line: false,
|
1077
|
-
)
|
1078
|
-
regexp = <<~INSPECTION.rstrip
|
1079
|
-
\\{
|
1080
|
-
state: :down,
|
1081
|
-
errors: \\[
|
1082
|
-
"Container A-234 is partially damaged",
|
1083
|
-
"Vessel B042 was attacked by raccoons",
|
1084
|
-
"Product FDK-3429 is out of stock"
|
1085
|
-
\\],
|
1086
|
-
mission_critical: true,
|
1087
|
-
serviceable: false,
|
1088
|
-
outstanding_orders: \\[
|
1089
|
-
#<SuperDiff::Test::Order:0x[a-z0-9]+ \\{
|
1090
|
-
@items=\\[
|
1091
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
1092
|
-
@name="ham",
|
1093
|
-
@quantity=1
|
1094
|
-
\\}>,
|
1095
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
1096
|
-
@name="eggs",
|
1097
|
-
@quantity=2
|
1098
|
-
\\}>,
|
1099
|
-
#<SuperDiff::Test::Item:0x[a-z0-9]+ \\{
|
1100
|
-
@name="cheese",
|
1101
|
-
@quantity=1
|
1102
|
-
\\}>
|
1103
|
-
\\]
|
1104
|
-
\\}>
|
1105
|
-
\\],
|
1106
|
-
customers: \\[
|
1107
|
-
#<SuperDiff::Test::Customer \\{
|
1108
|
-
name: "Marty McFly",
|
1109
|
-
shipping_address: #<SuperDiff::Test::ShippingAddress \\{
|
1110
|
-
line_1: "123 Baltic Ave.",
|
1111
|
-
line_2: "",
|
1112
|
-
city: "Hill Valley",
|
1113
|
-
state: "CA",
|
1114
|
-
zip: "90382"
|
1115
|
-
\\}>,
|
1116
|
-
phone: "111-111-1111"
|
1117
|
-
\\}>,
|
1118
|
-
#<SuperDiff::Test::Customer \\{
|
1119
|
-
name: "Doc Brown",
|
1120
|
-
shipping_address: #<SuperDiff::Test::ShippingAddress \\{
|
1121
|
-
line_1: "456 Park Place",
|
1122
|
-
line_2: "",
|
1123
|
-
city: "Beverly Hills",
|
1124
|
-
state: "CA",
|
1125
|
-
zip: "90210"
|
1126
|
-
\\}>,
|
1127
|
-
phone: "222-222-2222"
|
1128
|
-
\\}>
|
1129
|
-
\\]
|
1130
|
-
\\}
|
1131
|
-
INSPECTION
|
1132
|
-
expect(inspection).to match(/\A#{regexp}\Z/)
|
1133
|
-
end
|
1134
|
-
end
|
1135
|
-
end
|
1136
|
-
end
|
1137
|
-
|
1138
|
-
context "given a data structure that refers to itself somewhere inside of it" do
|
1139
|
-
context "given as_single_line: true" do
|
1140
|
-
it "replaces the reference with ∙∙∙" do
|
1141
|
-
value = ["a", "b", "c"]
|
1142
|
-
value.insert(1, value)
|
1143
|
-
inspection = described_class.inspect(value, as_single_line: true)
|
1144
|
-
expect(inspection).to eq(%(["a", ∙∙∙, "b", "c"]))
|
1145
|
-
end
|
1146
|
-
end
|
1147
|
-
|
1148
|
-
context "given as_single_line: false" do
|
1149
|
-
it "replaces the reference with ∙∙∙" do
|
1150
|
-
value = ["a", "b", "c"]
|
1151
|
-
value.insert(1, value)
|
1152
|
-
inspection = described_class.inspect(value, as_single_line: false)
|
1153
|
-
expect(inspection).to eq(<<~INSPECTION.rstrip)
|
1154
|
-
[
|
1155
|
-
"a",
|
1156
|
-
∙∙∙,
|
1157
|
-
"b",
|
1158
|
-
"c"
|
1159
|
-
]
|
1160
|
-
INSPECTION
|
1161
|
-
end
|
1162
|
-
end
|
1163
|
-
end
|
1164
|
-
|
1165
|
-
def colorize(*args, **opts, &block)
|
1166
|
-
SuperDiff::Helpers.style(*args, **opts, &block).to_s.chomp
|
1167
|
-
end
|
1168
|
-
end
|