super_diff 0.6.2 → 0.9.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 +0 -1
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -13
- 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/object_inspection/inspection_tree_builders.rb +16 -0
- data/lib/super_diff/active_record/object_inspection.rb +2 -6
- data/lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb +17 -0
- data/lib/super_diff/active_record/operation_tree_flatteners.rb +10 -0
- data/lib/super_diff/active_record/operation_trees/active_record_relation.rb +8 -7
- data/lib/super_diff/active_record.rb +7 -7
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -13
- data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +37 -0
- data/lib/super_diff/active_support/object_inspection/{inspectors.rb → inspection_tree_builders.rb} +2 -2
- data/lib/super_diff/active_support/object_inspection.rb +2 -6
- 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/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_trees/hash_with_indifferent_access.rb +4 -7
- data/lib/super_diff/active_support.rb +8 -8
- data/lib/super_diff/colorized_document_extensions.rb +9 -6
- data/lib/super_diff/configuration.rb +81 -8
- data/lib/super_diff/csi/four_bit_color.rb +0 -2
- data/lib/super_diff/csi.rb +1 -2
- 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 +2 -2
- data/lib/super_diff/equality_matchers/default.rb +2 -2
- data/lib/super_diff/equality_matchers/hash.rb +2 -2
- data/lib/super_diff/equality_matchers/multiline_string.rb +2 -2
- data/lib/super_diff/equality_matchers/primitive.rb +4 -7
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/helpers.rb +56 -2
- data/lib/super_diff/line.rb +83 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +183 -81
- 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/inspection_tree_builders.rb +44 -0
- 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/nodes.rb +33 -32
- 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/object_inspection.rb +12 -1
- 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/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_tree_flatteners.rb +20 -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/differs/collection_including.rb +4 -2
- data/lib/super_diff/rspec/differs/hash_including.rb +4 -2
- data/lib/super_diff/rspec/monkey_patches.rb +2 -2
- 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/object_inspection/inspection_tree_builders.rb +44 -0
- data/lib/super_diff/rspec/object_inspection.rb +4 -1
- data/lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb +0 -3
- 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/rspec.rb +34 -13
- 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/lib/super_diff.rb +28 -6
- data/spec/examples.txt +482 -403
- data/spec/integration/rails/active_support_spec.rb +19 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +12 -6
- data/spec/integration/rspec/eq_matcher_spec.rb +33 -87
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +17 -8
- data/spec/integration/rspec/match_array_matcher_spec.rb +14 -7
- data/spec/integration/rspec/match_matcher_spec.rb +93 -5
- data/spec/spec_helper.rb +4 -1
- data/spec/support/command_runner.rb +15 -25
- data/spec/support/helpers.rb +21 -0
- data/spec/support/integration/helpers.rb +2 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +3 -3
- data/spec/support/integration/test_programs/base.rb +36 -10
- data/spec/support/shared_examples/active_record.rb +3 -2
- 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 +16 -16
- data/spec/support/unit/helpers.rb +15 -0
- data/spec/support/unit/matchers/match_output.rb +41 -0
- data/spec/tmp/warnings_logger/all_warnings.txt +2 -0
- data/spec/unit/active_record/object_inspection_spec.rb +273 -0
- data/spec/unit/equality_matchers/main_spec.rb +55 -75
- data/spec/unit/helpers_spec.rb +75 -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 +1530 -800
- data/spec/unit/tiered_lines_elider_spec.rb +6356 -0
- data/spec/unit/tiered_lines_formatter_spec.rb +193 -0
- metadata +91 -52
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +0 -23
- data/lib/super_diff/active_record/diff_formatters.rb +0 -10
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +0 -16
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +0 -36
- data/lib/super_diff/active_support/diff_formatters.rb +0 -10
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +0 -28
- 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/diff_formatters.rb +0 -14
- 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/inspectors.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/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/lib/super_diff/rspec/object_inspection/inspectors.rb +0 -40
- data/spec/combustion/Gemfile.lock +0 -173
- data/spec/support/object_id.rb +0 -27
- data/spec/support/ruby_versions.rb +0 -11
@@ -12,7 +12,7 @@ module SuperDiff
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def removing_object_ids
|
15
|
-
first_replacing(/#<([\w:]+):0x[a-
|
15
|
+
first_replacing(/#<([\w:]+):0x[a-f0-9]+/, '#<\1')
|
16
16
|
self
|
17
17
|
end
|
18
18
|
|
@@ -38,10 +38,10 @@ module SuperDiff
|
|
38
38
|
message =
|
39
39
|
"Expected test to produce #{expect_output_to_contain_color? ? "colored" : "uncolored"} output, but it did not.\n\n" +
|
40
40
|
"Expected output to contain:\n\n" +
|
41
|
-
|
41
|
+
SuperDiff::Test::OutputHelpers.bookended(expected_output) +
|
42
42
|
"\n" +
|
43
43
|
"Actual output:\n\n" +
|
44
|
-
|
44
|
+
SuperDiff::Test::OutputHelpers.bookended(actual_output)
|
45
45
|
|
46
46
|
if ["1", "true"].include?(ENV["SHOW_DIFF"])
|
47
47
|
::RSpec::Matchers::ExpectedsForMultipleDiffs.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "attr_extras/explicit"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
module SuperDiff
|
4
5
|
module IntegrationTests
|
@@ -9,11 +10,15 @@ module SuperDiff
|
|
9
10
|
PROJECT_DIRECTORY = Pathname.new("../../../..").expand_path(__dir__)
|
10
11
|
TEMP_DIRECTORY = PROJECT_DIRECTORY.join("tmp")
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def initialize(
|
14
|
+
code,
|
15
|
+
color_enabled:,
|
16
|
+
configuration: {},
|
17
|
+
preserve_as_whole_file: false
|
18
|
+
)
|
15
19
|
@code = code.strip
|
16
20
|
@color_enabled = color_enabled
|
21
|
+
@configuration = configuration
|
17
22
|
@preserve_as_whole_file = preserve_as_whole_file
|
18
23
|
end
|
19
24
|
|
@@ -33,15 +38,27 @@ module SuperDiff
|
|
33
38
|
|
34
39
|
private
|
35
40
|
|
36
|
-
|
37
|
-
|
41
|
+
attr_reader :code, :configuration
|
42
|
+
|
43
|
+
def color_enabled?
|
44
|
+
@color_enabled
|
45
|
+
end
|
46
|
+
|
47
|
+
def preserve_as_whole_file?
|
48
|
+
@preserve_as_whole_file
|
49
|
+
end
|
38
50
|
|
39
51
|
def result_of_command
|
40
52
|
@_result_of_command ||=
|
41
53
|
if zeus_running?
|
42
|
-
Bundler.with_unbundled_env
|
54
|
+
Bundler.with_unbundled_env do
|
55
|
+
CommandRunner.run(Shellwords.join(command))
|
56
|
+
end
|
43
57
|
else
|
44
|
-
CommandRunner.run(
|
58
|
+
CommandRunner.run(
|
59
|
+
Shellwords.join(command),
|
60
|
+
env: { 'DISABLE_PRY' => 'true' },
|
61
|
+
)
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
@@ -51,7 +68,15 @@ module SuperDiff
|
|
51
68
|
end
|
52
69
|
|
53
70
|
if zeus_running?
|
54
|
-
[
|
71
|
+
[
|
72
|
+
"zeus",
|
73
|
+
test_plan_command,
|
74
|
+
color_option,
|
75
|
+
"--no-pry",
|
76
|
+
tempfile.to_s,
|
77
|
+
"--configuration",
|
78
|
+
JSON.generate(configuration),
|
79
|
+
]
|
55
80
|
else
|
56
81
|
[
|
57
82
|
"rspec",
|
@@ -67,7 +92,7 @@ module SuperDiff
|
|
67
92
|
end
|
68
93
|
|
69
94
|
def color_option
|
70
|
-
color_enabled ? "--color" : "--no-color"
|
95
|
+
color_enabled? ? "--color" : "--no-color"
|
71
96
|
end
|
72
97
|
|
73
98
|
def tempfile
|
@@ -88,7 +113,8 @@ module SuperDiff
|
|
88
113
|
|
89
114
|
test_plan = TestPlan.new(
|
90
115
|
using_outside_of_zeus: true,
|
91
|
-
color_enabled: #{color_enabled
|
116
|
+
color_enabled: #{color_enabled?.inspect},
|
117
|
+
configuration: #{configuration.inspect}
|
92
118
|
)
|
93
119
|
test_plan.boot
|
94
120
|
#{test_plan_prelude}
|
@@ -372,7 +372,7 @@ shared_examples_for "integration with ActiveRecord" do
|
|
372
372
|
expectation: proc {
|
373
373
|
line do
|
374
374
|
plain %|Expected |
|
375
|
-
actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, name: "Murphy"
|
375
|
+
actual %|[#<SuperDiff::Test::Models::ActiveRecord::Query @results=#<ActiveRecord::Relation [#<SuperDiff::Test::Models::ActiveRecord::Person id: 1, age: 20, name: "Murphy">]>>]|
|
376
376
|
end
|
377
377
|
|
378
378
|
line do
|
@@ -389,7 +389,8 @@ shared_examples_for "integration with ActiveRecord" do
|
|
389
389
|
# expected_line %|- age: 19,| # TODO
|
390
390
|
expected_line %|- age: 19|
|
391
391
|
actual_line %|+ age: 20,|
|
392
|
-
expected_line %|- name: "John"|
|
392
|
+
# expected_line %|- name: "John"| # TODO
|
393
|
+
expected_line %|- name: "John",|
|
393
394
|
actual_line %|+ name: "Murphy"|
|
394
395
|
plain_line %| }>|
|
395
396
|
plain_line %| ]>|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
shared_examples_for "integration with ActiveSupport" do
|
2
|
+
context "when comparing two different Time and ActiveSupport::TimeWithZone instances", active_record: true do
|
3
|
+
it "produces the correct failure message when used in the positive" do
|
4
|
+
as_both_colored_and_uncolored do |color_enabled|
|
5
|
+
snippet = <<~RUBY
|
6
|
+
expected = Time.utc(2011, 12, 13, 14, 15, 16)
|
7
|
+
actual = Time.utc(2011, 12, 13, 15, 15, 16).in_time_zone("Europe/Stockholm")
|
8
|
+
expect(expected).to eq(actual)
|
9
|
+
RUBY
|
10
|
+
program = make_rspec_rails_test_program(
|
11
|
+
snippet,
|
12
|
+
color_enabled: color_enabled,
|
13
|
+
)
|
14
|
+
|
15
|
+
expected_output = build_expected_output(
|
16
|
+
color_enabled: color_enabled,
|
17
|
+
snippet: %|expect(expected).to eq(actual)|,
|
18
|
+
expectation: proc {
|
19
|
+
line do
|
20
|
+
plain %|Expected |
|
21
|
+
actual %|#<Time 2011-12-13 14:15:16 +00:00 (UTC)>|
|
22
|
+
end
|
23
|
+
|
24
|
+
line do
|
25
|
+
plain %| to eq |
|
26
|
+
expected %|#<ActiveSupport::TimeWithZone 2011-12-13 16:15:16 +01:00 (CET)>|
|
27
|
+
end
|
28
|
+
},
|
29
|
+
diff: proc {
|
30
|
+
plain_line %| #<Time {|
|
31
|
+
plain_line %| year: 2011,|
|
32
|
+
plain_line %| month: 12,|
|
33
|
+
plain_line %| day: 13,|
|
34
|
+
expected_line %|- hour: 16,|
|
35
|
+
actual_line %|+ hour: 14,|
|
36
|
+
plain_line %| min: 15,|
|
37
|
+
plain_line %| sec: 16,|
|
38
|
+
plain_line %| subsec: 0,|
|
39
|
+
expected_line %|- zone: \"CET\",|
|
40
|
+
actual_line %|+ zone: \"UTC\",|
|
41
|
+
expected_line %|- utc_offset: 3600,|
|
42
|
+
actual_line %|+ utc_offset: 0,|
|
43
|
+
plain_line %| utc: #<Time {|
|
44
|
+
plain_line %| year: 2011,|
|
45
|
+
plain_line %| month: 12,|
|
46
|
+
plain_line %| day: 13,|
|
47
|
+
expected_line %|- hour: 15,|
|
48
|
+
actual_line %|+ hour: 14,|
|
49
|
+
plain_line %| min: 15,|
|
50
|
+
plain_line %| sec: 16,|
|
51
|
+
plain_line %| subsec: 0,|
|
52
|
+
plain_line %| zone: "UTC",|
|
53
|
+
plain_line %| utc_offset: 0|
|
54
|
+
plain_line %| }>|
|
55
|
+
plain_line %| }>|
|
56
|
+
},
|
57
|
+
)
|
58
|
+
|
59
|
+
expect(program).
|
60
|
+
to produce_output_when_run(expected_output).
|
61
|
+
in_color(color_enabled)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|