super_diff 0.4.2 → 0.6.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 +64 -24
- data/lib/super_diff.rb +20 -17
- data/lib/super_diff/active_record.rb +20 -24
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
- data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
- data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
- data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
- data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
- data/lib/super_diff/active_support.rb +16 -19
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
- data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
- data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
- data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
- data/lib/super_diff/colorized_document_extensions.rb +4 -4
- data/lib/super_diff/configuration.rb +70 -0
- data/lib/super_diff/csi.rb +2 -1
- data/lib/super_diff/diff_formatters.rb +3 -3
- data/lib/super_diff/diff_formatters/array.rb +3 -3
- data/lib/super_diff/diff_formatters/base.rb +3 -2
- data/lib/super_diff/diff_formatters/collection.rb +3 -3
- data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
- data/lib/super_diff/diff_formatters/default_object.rb +6 -8
- data/lib/super_diff/diff_formatters/defaults.rb +10 -0
- data/lib/super_diff/diff_formatters/hash.rb +3 -3
- data/lib/super_diff/diff_formatters/main.rb +41 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +7 -7
- data/lib/super_diff/differs.rb +4 -11
- data/lib/super_diff/differs/array.rb +2 -11
- data/lib/super_diff/differs/base.rb +20 -3
- data/lib/super_diff/differs/custom_object.rb +2 -11
- data/lib/super_diff/differs/default_object.rb +2 -8
- data/lib/super_diff/differs/defaults.rb +12 -0
- data/lib/super_diff/differs/hash.rb +2 -11
- data/lib/super_diff/differs/main.rb +48 -0
- data/lib/super_diff/differs/multiline_string.rb +2 -14
- data/lib/super_diff/differs/time_like.rb +15 -0
- data/lib/super_diff/equality_matchers.rb +3 -9
- data/lib/super_diff/equality_matchers/array.rb +3 -9
- data/lib/super_diff/equality_matchers/base.rb +1 -1
- data/lib/super_diff/equality_matchers/default.rb +3 -9
- data/lib/super_diff/equality_matchers/defaults.rb +12 -0
- data/lib/super_diff/equality_matchers/hash.rb +3 -9
- data/lib/super_diff/equality_matchers/main.rb +21 -0
- data/lib/super_diff/equality_matchers/multiline_string.rb +3 -9
- data/lib/super_diff/equality_matchers/primitive.rb +2 -2
- data/lib/super_diff/equality_matchers/singleline_string.rb +2 -2
- data/lib/super_diff/errors.rb +16 -0
- data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
- data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
- data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
- data/lib/super_diff/gem_version.rb +45 -0
- data/lib/super_diff/implementation_checks.rb +19 -0
- data/lib/super_diff/object_inspection.rb +1 -10
- data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
- data/lib/super_diff/object_inspection/inspectors.rb +5 -1
- data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
- data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
- data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
- data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
- data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
- data/lib/super_diff/operation_tree_builders.rb +18 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
- data/lib/super_diff/operation_tree_builders/base.rb +98 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
- data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
- data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
- data/lib/super_diff/operation_tree_builders/main.rb +42 -0
- data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
- data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
- data/lib/super_diff/operation_trees.rb +13 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/base.rb +9 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
- data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
- data/lib/super_diff/operation_trees/defaults.rb +5 -0
- data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
- data/lib/super_diff/operation_trees/main.rb +35 -0
- data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
- data/lib/super_diff/operations/unary_operation.rb +3 -0
- data/lib/super_diff/recursion_guard.rb +2 -0
- data/lib/super_diff/rspec.rb +49 -13
- data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
- data/lib/super_diff/rspec/differ.rb +2 -17
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -7
- data/lib/super_diff/rspec/differs/collection_including.rb +2 -7
- data/lib/super_diff/rspec/differs/hash_including.rb +2 -7
- data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -7
- 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/match.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +1 -1
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +6 -6
- data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
- data/lib/super_diff/rspec/monkey_patches.rb +23 -14
- data/lib/super_diff/rspec/object_inspection.rb +0 -1
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +15 -9
- data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +20 -10
- data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +20 -11
- data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
- data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +17 -6
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_including.rb +2 -2
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/hash_including.rb +3 -11
- data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/object_having_attributes.rb +4 -8
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +393 -393
- 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 +107 -107
- data/spec/integration/rspec/eq_matcher_spec.rb +230 -230
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +360 -233
- 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 +149 -107
- data/spec/integration/rspec/match_matcher_spec.rb +274 -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 +69 -13
- data/spec/spec_helper.rb +22 -13
- data/spec/support/command_runner.rb +3 -0
- data/spec/support/integration/helpers.rb +15 -95
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +15 -30
- data/spec/support/integration/test_programs/base.rb +122 -0
- data/spec/support/integration/test_programs/plain.rb +13 -0
- data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
- data/spec/support/integration/test_programs/rspec_active_support.rb +17 -0
- data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
- data/spec/support/models/active_record/person.rb +4 -11
- data/spec/support/models/active_record/shipping_address.rb +10 -14
- data/spec/support/object_id.rb +6 -5
- data/spec/support/shared_examples/active_record.rb +108 -108
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +196 -232
- data/spec/tmp/integration_spec.rb +15 -0
- data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +518 -362
- data/spec/unit/object_inspection_spec.rb +77 -1
- data/super_diff.gemspec +3 -2
- metadata +83 -54
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
- data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
- data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
- data/lib/super_diff/diff_formatter.rb +0 -32
- data/lib/super_diff/differ.rb +0 -51
- data/lib/super_diff/differs/time.rb +0 -24
- data/lib/super_diff/equality_matcher.rb +0 -32
- data/lib/super_diff/no_differ_available_error.rb +0 -22
- data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
- data/lib/super_diff/object_inspection/inspector.rb +0 -27
- data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
- data/lib/super_diff/object_inspection/map.rb +0 -30
- data/lib/super_diff/operation_sequences.rb +0 -9
- data/lib/super_diff/operational_sequencer.rb +0 -48
- data/lib/super_diff/operational_sequencers.rb +0 -17
- data/lib/super_diff/operational_sequencers/base.rb +0 -89
- data/lib/super_diff/operational_sequencers/hash.rb +0 -85
- data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
- data/lib/super_diff/rspec/configuration.rb +0 -31
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
- data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
@@ -23,7 +23,7 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
23
23
|
red_line "Here is the next line."
|
24
24
|
plain_line " This part is indented, for whatever reason. It just kinda keeps"
|
25
25
|
plain_line " going until we finish saying whatever it is we want to say."
|
26
|
-
}
|
26
|
+
},
|
27
27
|
)
|
28
28
|
|
29
29
|
expect(program).
|
@@ -50,10 +50,10 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
50
50
|
snippet: %|expect(:anything).to fail_with_paragraphed_failure_message|,
|
51
51
|
newline_before_expectation: true,
|
52
52
|
expectation: proc {
|
53
|
-
red_line
|
53
|
+
red_line "This is a message that spans multiple paragraphs."
|
54
54
|
newline
|
55
55
|
plain_line "Here is the next paragraph."
|
56
|
-
}
|
56
|
+
},
|
57
57
|
)
|
58
58
|
|
59
59
|
expect(program).
|
@@ -81,7 +81,7 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
81
81
|
expectation: proc {
|
82
82
|
red_line "This is a message that spans multiple lines."
|
83
83
|
red_line "Here is the next line."
|
84
|
-
}
|
84
|
+
},
|
85
85
|
)
|
86
86
|
|
87
87
|
expect(program).
|
@@ -142,7 +142,7 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
142
142
|
red_line "Here is the next line."
|
143
143
|
plain_line " This part is indented, for whatever reason. It just kinda keeps"
|
144
144
|
plain_line " going until we finish saying whatever it is we want to say."
|
145
|
-
}
|
145
|
+
},
|
146
146
|
)
|
147
147
|
|
148
148
|
expect(program).
|
@@ -171,8 +171,8 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
171
171
|
expectation: proc {
|
172
172
|
red_line "This is a message that spans multiple paragraphs."
|
173
173
|
newline
|
174
|
-
plain_line
|
175
|
-
}
|
174
|
+
plain_line "Here is the next paragraph."
|
175
|
+
},
|
176
176
|
)
|
177
177
|
|
178
178
|
expect(program).
|
@@ -228,7 +228,7 @@ RSpec.describe "Integration with a third-party matcher", type: :integration do
|
|
228
228
|
snippet: %|expect(:anything).not_to pass_with_singleline_failure_message|,
|
229
229
|
expectation: proc {
|
230
230
|
red_line "This is a message that spans only one line."
|
231
|
-
}
|
231
|
+
},
|
232
232
|
)
|
233
233
|
|
234
234
|
expect(program).
|
@@ -15,17 +15,17 @@ RSpec.describe "Integration with RSpec and unhandled errors", type: :integration
|
|
15
15
|
|
16
16
|
expected_output = build_expected_output(
|
17
17
|
color_enabled: color_enabled,
|
18
|
-
snippet:
|
18
|
+
snippet: snippet,
|
19
19
|
newline_before_expectation: true,
|
20
20
|
indentation: 5,
|
21
21
|
expectation: proc {
|
22
22
|
red_line "RuntimeError:"
|
23
23
|
indent by: 2 do
|
24
|
-
red_line
|
24
|
+
red_line "Some kind of error or whatever"
|
25
25
|
newline
|
26
26
|
plain_line "This is another line"
|
27
27
|
end
|
28
|
-
}
|
28
|
+
},
|
29
29
|
)
|
30
30
|
|
31
31
|
expect(program).
|
@@ -48,7 +48,7 @@ RSpec.describe "Integration with RSpec and unhandled errors", type: :integration
|
|
48
48
|
|
49
49
|
expected_output = build_expected_output(
|
50
50
|
color_enabled: color_enabled,
|
51
|
-
snippet:
|
51
|
+
snippet: snippet,
|
52
52
|
newline_before_expectation: true,
|
53
53
|
indentation: 5,
|
54
54
|
expectation: proc {
|
@@ -56,7 +56,7 @@ RSpec.describe "Integration with RSpec and unhandled errors", type: :integration
|
|
56
56
|
indent by: 2 do
|
57
57
|
red_line "Some kind of error or whatever"
|
58
58
|
end
|
59
|
-
}
|
59
|
+
},
|
60
60
|
)
|
61
61
|
|
62
62
|
expect(program).
|
@@ -67,23 +67,79 @@ RSpec.describe "Integration with RSpec and unhandled errors", type: :integration
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context "when multiple
|
71
|
-
it "highlights the first line in red
|
70
|
+
context "when multiple exceptions occur" do
|
71
|
+
it "displays all exceptions, and for each exception, highlights the first line in red and leaves the rest of the message alone" do
|
72
72
|
as_both_colored_and_uncolored do |color_enabled|
|
73
|
-
|
74
|
-
|
73
|
+
snippet = <<~TEST.strip
|
74
|
+
raise "Some kind of error or whatever\\n\\nThis is another line"
|
75
|
+
TEST
|
76
|
+
code = <<~CODE
|
75
77
|
RSpec.describe "test" do
|
76
78
|
after(:each) do
|
77
|
-
|
79
|
+
#{snippet}
|
78
80
|
end
|
81
|
+
|
79
82
|
it "passes" do
|
80
|
-
|
83
|
+
#{snippet}
|
81
84
|
end
|
82
85
|
end
|
83
|
-
|
86
|
+
CODE
|
87
|
+
|
88
|
+
program = make_plain_test_program(
|
89
|
+
code,
|
90
|
+
color_enabled: color_enabled,
|
91
|
+
preserve_as_whole_file: true,
|
92
|
+
)
|
93
|
+
|
94
|
+
expected_output1 = colored(color_enabled: color_enabled) do
|
95
|
+
indent by: 5 do
|
96
|
+
line do
|
97
|
+
plain "1.1) "
|
98
|
+
bold "Failure/Error: "
|
99
|
+
plain snippet
|
100
|
+
end
|
101
|
+
|
102
|
+
newline
|
103
|
+
|
104
|
+
indent by: 5 do
|
105
|
+
red_line "RuntimeError:"
|
106
|
+
indent by: 2 do
|
107
|
+
red_line "Some kind of error or whatever"
|
108
|
+
newline
|
109
|
+
line "This is another line"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
expected_output2 = colored(color_enabled: color_enabled) do
|
116
|
+
indent by: 5 do
|
117
|
+
line do
|
118
|
+
plain "1.2) "
|
119
|
+
bold "Failure/Error: "
|
120
|
+
plain snippet
|
121
|
+
end
|
122
|
+
|
123
|
+
newline
|
124
|
+
|
125
|
+
indent by: 5 do
|
126
|
+
red_line "RuntimeError:"
|
127
|
+
indent by: 2 do
|
128
|
+
red_line "Some kind of error or whatever"
|
129
|
+
newline
|
130
|
+
line "This is another line"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
expect(program).
|
137
|
+
to produce_output_when_run(expected_output1).
|
138
|
+
in_color(color_enabled)
|
84
139
|
|
85
140
|
expect(program).
|
86
|
-
to produce_output_when_run(
|
141
|
+
to produce_output_when_run(expected_output2).
|
142
|
+
in_color(color_enabled)
|
87
143
|
end
|
88
144
|
end
|
89
145
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ begin
|
|
8
8
|
rescue LoadError
|
9
9
|
end
|
10
10
|
|
11
|
+
require "pp"
|
12
|
+
|
11
13
|
#---
|
12
14
|
|
13
15
|
require_relative "../support/current_bundle"
|
@@ -18,26 +20,25 @@ SuperDiff::CurrentBundle.instance.assert_appraisal!
|
|
18
20
|
|
19
21
|
begin
|
20
22
|
require "active_record"
|
23
|
+
|
21
24
|
active_record_available = true
|
22
|
-
rescue LoadError
|
23
|
-
active_record_available = false
|
24
|
-
end
|
25
25
|
|
26
|
-
if active_record_available
|
27
26
|
ActiveRecord::Base.establish_connection(
|
28
27
|
adapter: "sqlite3",
|
29
28
|
database: ":memory:",
|
30
29
|
)
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
require "super_diff/rspec"
|
30
|
+
rescue LoadError
|
31
|
+
active_record_available = false
|
35
32
|
end
|
36
33
|
|
37
|
-
Dir.glob(File.expand_path("support/**/*.rb", __dir__)).
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
Dir.glob(File.expand_path("support/**/*.rb", __dir__)).
|
35
|
+
sort.
|
36
|
+
reject do |file|
|
37
|
+
file.include?("/models/active_record/") && !active_record_available
|
38
|
+
end.
|
39
|
+
each do |file|
|
40
|
+
require file
|
41
|
+
end
|
41
42
|
|
42
43
|
RSpec.configure do |config|
|
43
44
|
config.include(SuperDiff::IntegrationTests, type: :integration)
|
@@ -65,6 +66,14 @@ RSpec.configure do |config|
|
|
65
66
|
|
66
67
|
config.order = :random
|
67
68
|
Kernel.srand config.seed
|
69
|
+
|
70
|
+
if ENV["CI"] == "true"
|
71
|
+
config.color_mode = :on
|
72
|
+
end
|
68
73
|
end
|
69
74
|
|
70
|
-
|
75
|
+
if active_record_available
|
76
|
+
require "super_diff/rspec-rails"
|
77
|
+
else
|
78
|
+
require "super_diff/rspec"
|
79
|
+
end
|
@@ -120,6 +120,9 @@ Output:
|
|
120
120
|
@env = extract_env_from(@options)
|
121
121
|
|
122
122
|
@process = ChildProcess.build(*command)
|
123
|
+
# @env.each do |key, value|
|
124
|
+
# @process.environment[key] = value
|
125
|
+
# end
|
123
126
|
@process.io.stdout = @process.io.stderr = @writer
|
124
127
|
|
125
128
|
@wrapper = -> (block) { block.call }
|
@@ -8,104 +8,28 @@ module SuperDiff
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def make_plain_test_program(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def make_plain_test_program(
|
12
|
+
test,
|
13
|
+
color_enabled:,
|
14
|
+
preserve_as_whole_file: false
|
15
|
+
)
|
16
|
+
TestPrograms::Plain.new(
|
17
|
+
test,
|
18
|
+
color_enabled: color_enabled,
|
19
|
+
preserve_as_whole_file: preserve_as_whole_file,
|
20
|
+
)
|
16
21
|
end
|
17
22
|
|
18
23
|
def make_rspec_active_record_program(test, color_enabled:)
|
19
|
-
|
20
|
-
#{
|
21
|
-
set_up_active_record_around do
|
22
|
-
set_up_with(
|
23
|
-
"super_diff/rspec", "super_diff/active_record",
|
24
|
-
color_enabled: color_enabled
|
25
|
-
)
|
26
|
-
end
|
27
|
-
}
|
28
|
-
#{describe_block_including(test)}
|
29
|
-
PROGRAM
|
30
|
-
end
|
31
|
-
|
32
|
-
def make_rspec_rails_test_program(test, color_enabled:)
|
33
|
-
<<~PROGRAM
|
34
|
-
#{
|
35
|
-
set_up_active_record_around do
|
36
|
-
set_up_with("super_diff/rspec-rails", color_enabled: color_enabled)
|
37
|
-
end
|
38
|
-
}
|
39
|
-
#{describe_block_including(test)}
|
40
|
-
PROGRAM
|
41
|
-
end
|
42
|
-
|
43
|
-
def set_up_active_record_around(&block)
|
44
|
-
<<~PROGRAM
|
45
|
-
require "active_record"
|
46
|
-
|
47
|
-
ActiveRecord::Base.establish_connection(
|
48
|
-
adapter: "sqlite3",
|
49
|
-
database: ":memory:"
|
50
|
-
)
|
51
|
-
|
52
|
-
RSpec.configuration do |config|
|
53
|
-
config.before do
|
54
|
-
SuperDiff::Test::Models::ActiveRecord::Person.delete_all
|
55
|
-
SuperDiff::Test::Models::ActiveRecord::ShippingAddress.delete_all
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
#{block.call}
|
60
|
-
|
61
|
-
Dir.glob(SUPPORT_DIR.join("models/active_record/*.rb")).each do |path|
|
62
|
-
require path
|
63
|
-
end
|
64
|
-
PROGRAM
|
24
|
+
TestPrograms::RSpecActiveRecord.new(test, color_enabled: color_enabled)
|
65
25
|
end
|
66
26
|
|
67
|
-
def
|
68
|
-
|
69
|
-
PROJECT_DIRECTORY = Pathname.new("#{PROJECT_DIRECTORY}")
|
70
|
-
SUPPORT_DIR = PROJECT_DIRECTORY.join("spec/support")
|
71
|
-
INSIDE_INTEGRATION_TEST = true
|
72
|
-
|
73
|
-
$LOAD_PATH.unshift(PROJECT_DIRECTORY.join("lib"))
|
74
|
-
#\$LOAD_PATH.unshift(PROJECT_DIRECTORY)
|
75
|
-
|
76
|
-
begin
|
77
|
-
require "pry-byebug"
|
78
|
-
rescue LoadError
|
79
|
-
require "pry-nav"
|
80
|
-
end
|
81
|
-
|
82
|
-
module SuperDiff
|
83
|
-
module IntegrationTests; end
|
84
|
-
end
|
85
|
-
|
86
|
-
RSpec.configure do |config|
|
87
|
-
config.color_mode = :#{color_enabled ? "on" : "off"}
|
88
|
-
config.include SuperDiff::IntegrationTests
|
89
|
-
end
|
90
|
-
|
91
|
-
#{libraries.map { |library| %( require "#{library}") }.join("\n")}
|
92
|
-
|
93
|
-
Dir.glob(SUPPORT_DIR.join("{models,matchers}/*.rb")).each do |path|
|
94
|
-
require path
|
95
|
-
end
|
96
|
-
|
97
|
-
require SUPPORT_DIR.join("integration/matchers")
|
98
|
-
SETUP
|
27
|
+
def make_rspec_active_support_program(test, color_enabled:)
|
28
|
+
TestPrograms::RSpecActiveSupport.new(test, color_enabled: color_enabled)
|
99
29
|
end
|
100
30
|
|
101
|
-
def
|
102
|
-
|
103
|
-
RSpec.describe "test" do
|
104
|
-
it "passes" do
|
105
|
-
#{reindent(test, level: 2)}
|
106
|
-
end
|
107
|
-
end
|
108
|
-
PROGRAM
|
31
|
+
def make_rspec_rails_test_program(test, color_enabled:)
|
32
|
+
TestPrograms::RSpecRails.new(test, color_enabled: color_enabled)
|
109
33
|
end
|
110
34
|
|
111
35
|
def build_expected_output(
|
@@ -179,9 +103,5 @@ module SuperDiff
|
|
179
103
|
def colored(color_enabled: true, &block)
|
180
104
|
SuperDiff::Helpers.style(color_enabled: color_enabled, &block).to_s.chomp
|
181
105
|
end
|
182
|
-
|
183
|
-
def reindent(code, level: 0)
|
184
|
-
code.strip.split("\n").map { |line| (" " * level) + line }.join("\n")
|
185
|
-
end
|
186
106
|
end
|
187
107
|
end
|
@@ -5,11 +5,8 @@ module SuperDiff
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class ProduceOutputWhenRunMatcher
|
8
|
-
PROJECT_DIRECTORY = Pathname.new("../../../../../").expand_path(__FILE__)
|
9
|
-
TEMP_DIRECTORY = PROJECT_DIRECTORY.join("tmp")
|
10
|
-
|
11
8
|
def initialize(expected_output)
|
12
|
-
@expected_output = expected_output.to_s
|
9
|
+
@expected_output = expected_output.to_s
|
13
10
|
@output_processor = nil
|
14
11
|
@expect_output_to_contain_color = nil
|
15
12
|
end
|
@@ -25,9 +22,7 @@ module SuperDiff
|
|
25
22
|
end
|
26
23
|
|
27
24
|
def matches?(program)
|
28
|
-
@program = program
|
29
|
-
|
30
|
-
TEMP_DIRECTORY.mkpath
|
25
|
+
@program = program
|
31
26
|
|
32
27
|
output_matches? && presence_of_color_matches?
|
33
28
|
end
|
@@ -41,20 +36,24 @@ module SuperDiff
|
|
41
36
|
"."
|
42
37
|
else
|
43
38
|
message =
|
44
|
-
"Expected test to produce output, but it did not.\n\n" +
|
39
|
+
"Expected test to produce #{expect_output_to_contain_color? ? "colored" : "uncolored"} output, but it did not.\n\n" +
|
45
40
|
"Expected output to contain:\n\n" +
|
46
41
|
CommandRunner::OutputHelpers.bookended(expected_output) +
|
47
42
|
"\n" +
|
48
43
|
"Actual output:\n\n" +
|
49
44
|
CommandRunner::OutputHelpers.bookended(actual_output)
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
if ["1", "true"].include?(ENV["SHOW_DIFF"])
|
47
|
+
::RSpec::Matchers::ExpectedsForMultipleDiffs.
|
48
|
+
from(expected_output).
|
49
|
+
message_with_diff(
|
50
|
+
message,
|
51
|
+
::RSpec::Expectations.differ,
|
52
|
+
actual_output,
|
53
|
+
)
|
54
|
+
else
|
55
|
+
message
|
56
|
+
end
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
@@ -77,7 +76,7 @@ module SuperDiff
|
|
77
76
|
|
78
77
|
def actual_output
|
79
78
|
@_actual_output ||= begin
|
80
|
-
output =
|
79
|
+
output = program.run.output.strip
|
81
80
|
|
82
81
|
if output_processor
|
83
82
|
output.gsub!(output_processor[0], output_processor[1])
|
@@ -87,20 +86,6 @@ module SuperDiff
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
def run_command
|
91
|
-
CommandRunner.run(
|
92
|
-
"rspec --options /tmp/dummy-rspec-config",
|
93
|
-
tempfile.to_s,
|
94
|
-
env: { "DISABLE_PRY" => "true" },
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
def tempfile
|
99
|
-
@_tempfile =
|
100
|
-
TEMP_DIRECTORY.join("integration_spec.rb").
|
101
|
-
tap { |tempfile| tempfile.write(program) }
|
102
|
-
end
|
103
|
-
|
104
89
|
def presence_of_color_matches?
|
105
90
|
@expect_output_to_contain_color.nil? ||
|
106
91
|
output_has_color? == expect_output_to_contain_color?
|