super_diff 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +117 -89
- data/lib/super_diff.rb +33 -47
- data/lib/super_diff/active_record.rb +41 -0
- data/lib/super_diff/active_record/diff_formatters.rb +10 -0
- data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +23 -0
- data/lib/super_diff/active_record/differs.rb +10 -0
- data/lib/super_diff/active_record/differs/active_record_relation.rb +30 -0
- data/lib/super_diff/active_record/object_inspection.rb +14 -0
- data/lib/super_diff/active_record/object_inspection/inspectors.rb +16 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +38 -0
- data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +18 -0
- data/lib/super_diff/active_record/object_inspection/map_extension.rb +18 -0
- data/lib/super_diff/active_record/operation_sequences.rb +10 -0
- data/lib/super_diff/active_record/operation_sequences/active_record_relation.rb +16 -0
- data/lib/super_diff/active_record/operational_sequencers.rb +14 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_model.rb +19 -0
- data/lib/super_diff/active_record/operational_sequencers/active_record_relation.rb +24 -0
- data/lib/super_diff/active_support.rb +33 -0
- data/lib/super_diff/active_support/diff_formatters.rb +10 -0
- data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/differs.rb +10 -0
- data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +36 -0
- data/lib/super_diff/active_support/object_inspection.rb +14 -0
- data/lib/super_diff/active_support/object_inspection/inspectors.rb +12 -0
- data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +18 -0
- data/lib/super_diff/active_support/object_inspection/map_extension.rb +15 -0
- data/lib/super_diff/active_support/operation_sequences.rb +10 -0
- data/lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb +16 -0
- data/lib/super_diff/active_support/operational_sequencers.rb +10 -0
- data/lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb +21 -0
- data/lib/super_diff/colorized_document_extensions.rb +17 -0
- data/lib/super_diff/csi.rb +45 -15
- data/lib/super_diff/csi/bold_sequence.rb +9 -0
- data/lib/super_diff/csi/color.rb +62 -0
- data/lib/super_diff/csi/color_sequence_block.rb +28 -0
- data/lib/super_diff/csi/colorized_document.rb +72 -0
- data/lib/super_diff/csi/document.rb +183 -0
- data/lib/super_diff/csi/eight_bit_color.rb +72 -26
- data/lib/super_diff/csi/four_bit_color.rb +63 -29
- data/lib/super_diff/csi/twenty_four_bit_color.rb +79 -18
- data/lib/super_diff/csi/uncolorized_document.rb +29 -0
- data/lib/super_diff/diff_formatter.rb +10 -15
- data/lib/super_diff/diff_formatters.rb +10 -1
- data/lib/super_diff/diff_formatters/base.rb +12 -17
- data/lib/super_diff/diff_formatters/collection.rb +81 -50
- data/lib/super_diff/diff_formatters/{object.rb → custom_object.rb} +12 -9
- data/lib/super_diff/diff_formatters/default_object.rb +48 -0
- data/lib/super_diff/diff_formatters/multiline_string.rb +31 -0
- data/lib/super_diff/differ.rb +35 -32
- data/lib/super_diff/differs.rb +16 -1
- data/lib/super_diff/differs/array.rb +2 -2
- data/lib/super_diff/differs/base.rb +11 -21
- data/lib/super_diff/differs/custom_object.rb +26 -0
- data/lib/super_diff/differs/default_object.rb +25 -0
- data/lib/super_diff/differs/empty.rb +1 -1
- data/lib/super_diff/differs/hash.rb +2 -2
- data/lib/super_diff/differs/{multi_line_string.rb → multiline_string.rb} +6 -5
- data/lib/super_diff/equality_matcher.rb +9 -22
- data/lib/super_diff/equality_matchers.rb +19 -1
- data/lib/super_diff/equality_matchers/array.rb +6 -4
- data/lib/super_diff/equality_matchers/base.rb +8 -16
- data/lib/super_diff/equality_matchers/default.rb +60 -0
- data/lib/super_diff/equality_matchers/hash.rb +6 -4
- data/lib/super_diff/equality_matchers/{multi_line_string.rb → multiline_string.rb} +9 -6
- data/lib/super_diff/equality_matchers/primitive.rb +34 -0
- data/lib/super_diff/equality_matchers/{single_line_string.rb → singleline_string.rb} +7 -5
- data/lib/super_diff/helpers.rb +17 -81
- data/lib/super_diff/no_differ_available_error.rb +22 -0
- data/lib/super_diff/{errors.rb → no_operational_sequencer_available_error.rb} +0 -0
- data/lib/super_diff/object_inspection.rb +24 -0
- data/lib/super_diff/object_inspection/inspection_tree.rb +144 -0
- data/lib/super_diff/object_inspection/inspector.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors.rb +18 -0
- data/lib/super_diff/object_inspection/inspectors/array.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/custom_object.rb +27 -0
- data/lib/super_diff/object_inspection/inspectors/default_object.rb +47 -0
- data/lib/super_diff/object_inspection/inspectors/hash.rb +22 -0
- data/lib/super_diff/object_inspection/inspectors/primitive.rb +13 -0
- data/lib/super_diff/object_inspection/inspectors/string.rb +13 -0
- data/lib/super_diff/object_inspection/map.rb +28 -0
- data/lib/super_diff/object_inspection/nodes.rb +49 -0
- data/lib/super_diff/object_inspection/nodes/base.rb +86 -0
- data/lib/super_diff/object_inspection/nodes/break.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/inspection.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/nesting.rb +16 -0
- data/lib/super_diff/object_inspection/nodes/text.rb +15 -0
- data/lib/super_diff/object_inspection/nodes/when_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_multiline.rb +22 -0
- data/lib/super_diff/object_inspection/nodes/when_non_empty.rb +30 -0
- data/lib/super_diff/object_inspection/nodes/when_singleline.rb +24 -0
- data/lib/super_diff/operation_sequences.rb +9 -0
- data/lib/super_diff/operation_sequences/base.rb +1 -1
- data/lib/super_diff/operation_sequences/{object.rb → custom_object.rb} +4 -3
- data/lib/super_diff/operation_sequences/default_object.rb +25 -0
- data/lib/super_diff/operational_sequencer.rb +23 -18
- data/lib/super_diff/operational_sequencers.rb +12 -1
- data/lib/super_diff/operational_sequencers/array.rb +65 -62
- data/lib/super_diff/operational_sequencers/base.rb +18 -26
- data/lib/super_diff/operational_sequencers/custom_object.rb +35 -0
- data/lib/super_diff/operational_sequencers/{object.rb → default_object.rb} +21 -11
- data/lib/super_diff/operational_sequencers/hash.rb +8 -5
- data/lib/super_diff/operational_sequencers/{multi_line_string.rb → multiline_string.rb} +11 -6
- data/lib/super_diff/operations.rb +6 -0
- data/lib/super_diff/operations/binary_operation.rb +14 -34
- data/lib/super_diff/operations/unary_operation.rb +11 -2
- data/lib/super_diff/rails.rb +1 -0
- data/lib/super_diff/recursion_guard.rb +47 -0
- data/lib/super_diff/rspec-rails.rb +2 -0
- data/lib/super_diff/rspec.rb +52 -8
- data/lib/super_diff/rspec/augmented_matcher.rb +98 -0
- data/lib/super_diff/rspec/configuration.rb +31 -0
- data/lib/super_diff/rspec/differ.rb +60 -16
- data/lib/super_diff/rspec/differs.rb +13 -0
- data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +23 -0
- data/lib/super_diff/rspec/differs/partial_array.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_hash.rb +22 -0
- data/lib/super_diff/rspec/differs/partial_object.rb +22 -0
- data/lib/super_diff/rspec/matcher_text_builders.rb +24 -0
- data/lib/super_diff/rspec/matcher_text_builders/base.rb +155 -0
- data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +78 -0
- data/lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb +14 -0
- data/lib/super_diff/rspec/matcher_text_builders/match.rb +23 -0
- data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -0
- data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +99 -0
- data/lib/super_diff/rspec/matcher_text_template.rb +240 -0
- data/lib/super_diff/rspec/monkey_patches.rb +601 -98
- data/lib/super_diff/rspec/object_inspection.rb +8 -0
- data/lib/super_diff/rspec/object_inspection/inspectors.rb +24 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +19 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +22 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +21 -0
- data/lib/super_diff/rspec/object_inspection/map_extension.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers.rb +22 -0
- data/lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb +97 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_array.rb +23 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +32 -0
- data/lib/super_diff/rspec/operational_sequencers/partial_object.rb +64 -0
- data/lib/super_diff/version.rb +1 -1
- data/spec/examples.txt +328 -46
- data/spec/integration/rails/active_record_spec.rb +19 -0
- data/spec/integration/rails/hash_with_indifferent_access_spec.rb +19 -0
- data/spec/integration/rspec/be_falsey_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_matcher_spec.rb +565 -0
- data/spec/integration/rspec/be_nil_matcher_spec.rb +53 -0
- data/spec/integration/rspec/be_predicate_matcher_spec.rb +546 -0
- data/spec/integration/rspec/be_truthy_matcher_spec.rb +57 -0
- data/spec/integration/rspec/contain_exactly_matcher_spec.rb +368 -0
- data/spec/integration/rspec/eq_matcher_spec.rb +874 -0
- data/spec/integration/rspec/have_attributes_matcher_spec.rb +299 -0
- data/spec/integration/rspec/include_matcher_spec.rb +350 -0
- data/spec/integration/rspec/match_matcher_spec.rb +1258 -0
- data/spec/integration/rspec/raise_error_matcher_spec.rb +350 -0
- data/spec/integration/rspec/respond_to_matcher_spec.rb +994 -0
- data/spec/integration/rspec/unhandled_errors_spec.rb +94 -0
- data/spec/spec_helper.rb +19 -4
- data/spec/support/colorizer.rb +9 -0
- data/spec/support/command_runner.rb +4 -0
- data/spec/support/integration/helpers.rb +179 -0
- data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +79 -41
- data/spec/support/models/a.rb +11 -0
- data/spec/support/models/active_record/person.rb +26 -0
- data/spec/support/models/active_record/shipping_address.rb +29 -0
- data/spec/support/models/customer.rb +24 -0
- data/spec/support/models/empty_class.rb +6 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/order.rb +9 -0
- data/spec/support/models/person.rb +20 -0
- data/spec/support/models/player.rb +33 -0
- data/spec/support/models/shipping_address.rb +34 -0
- data/spec/support/ruby_versions.rb +7 -0
- data/spec/support/shared_examples/active_record.rb +338 -0
- data/spec/support/shared_examples/hash_with_indifferent_access.rb +233 -0
- data/spec/unit/equality_matcher_spec.rb +579 -171
- data/spec/unit/object_inspection_spec.rb +1092 -0
- data/spec/unit/rspec/matchers/be_compared_to_spec.rb +23 -0
- data/spec/unit/rspec/matchers/be_falsey_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_nil_spec.rb +9 -0
- data/spec/unit/rspec/matchers/be_predicate_spec.rb +31 -0
- data/spec/unit/rspec/matchers/be_spec.rb +17 -0
- data/spec/unit/rspec/matchers/be_truthy_spec.rb +9 -0
- data/spec/unit/rspec/matchers/contain_exactly_spec.rb +11 -0
- data/spec/unit/rspec/matchers/eq_spec.rb +9 -0
- data/spec/unit/rspec/matchers/have_attributes_spec.rb +11 -0
- data/spec/unit/rspec/matchers/include_spec.rb +21 -0
- data/spec/unit/rspec/matchers/match_spec.rb +9 -0
- data/spec/unit/rspec/matchers/raise_error_spec.rb +29 -0
- data/spec/unit/rspec/matchers/respond_to_spec.rb +78 -0
- data/super_diff.gemspec +4 -2
- metadata +231 -34
- data/lib/super_diff/csi/color_helper.rb +0 -52
- data/lib/super_diff/csi/eight_bit_sequence.rb +0 -27
- data/lib/super_diff/csi/four_bit_sequence.rb +0 -24
- data/lib/super_diff/csi/sequence.rb +0 -22
- data/lib/super_diff/csi/twenty_four_bit_sequence.rb +0 -27
- data/lib/super_diff/diff_formatters/multi_line_string.rb +0 -31
- data/lib/super_diff/differs/object.rb +0 -68
- data/lib/super_diff/equality_matchers/object.rb +0 -18
- data/lib/super_diff/value_inspection.rb +0 -11
- data/spec/integration/rspec_spec.rb +0 -261
- data/spec/support/color_helper.rb +0 -49
- data/spec/support/person.rb +0 -23
- data/spec/support/person_diff_formatter.rb +0 -15
- data/spec/support/person_operation_sequence.rb +0 -14
- data/spec/support/person_operational_sequencer.rb +0 -19
@@ -0,0 +1,350 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe "Integration with RSpec's #raise_error matcher", type: :integration do
|
4
|
+
context "given only an exception class" do
|
5
|
+
it "produces the correct failure message when used in the positive" do
|
6
|
+
as_both_colored_and_uncolored do |color_enabled|
|
7
|
+
snippet = <<~TEST.strip
|
8
|
+
expect { raise StandardError.new('boo') }.to raise_error(RuntimeError)
|
9
|
+
TEST
|
10
|
+
program = make_plain_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 { raise StandardError.new('boo') }.to raise_error(RuntimeError)|,
|
18
|
+
expectation: proc {
|
19
|
+
line do
|
20
|
+
plain "Expected raised exception "
|
21
|
+
beta %|#<StandardError "boo">|
|
22
|
+
plain " to match "
|
23
|
+
alpha %|#<RuntimeError>|
|
24
|
+
plain "."
|
25
|
+
end
|
26
|
+
},
|
27
|
+
)
|
28
|
+
|
29
|
+
expect(program).
|
30
|
+
to produce_output_when_run(expected_output).
|
31
|
+
in_color(color_enabled)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "produces the correct failure message when used in the negative" do
|
36
|
+
as_both_colored_and_uncolored do |color_enabled|
|
37
|
+
snippet = <<~TEST.strip
|
38
|
+
expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)
|
39
|
+
TEST
|
40
|
+
program = make_plain_test_program(
|
41
|
+
snippet,
|
42
|
+
color_enabled: color_enabled,
|
43
|
+
)
|
44
|
+
|
45
|
+
expected_output = build_expected_output(
|
46
|
+
color_enabled: color_enabled,
|
47
|
+
snippet: %|expect { raise StandardError.new('boo') }.not_to raise_error(StandardError)|,
|
48
|
+
expectation: proc {
|
49
|
+
line do
|
50
|
+
plain "Expected raised exception "
|
51
|
+
beta %|#<StandardError "boo">|
|
52
|
+
plain " not to match "
|
53
|
+
alpha %|#<StandardError>|
|
54
|
+
plain "."
|
55
|
+
end
|
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
|
+
|
66
|
+
context "with only a message (and assuming a RuntimeError)" do
|
67
|
+
context "when the message is short" do
|
68
|
+
it "produces the correct failure message when used in the positive" do
|
69
|
+
as_both_colored_and_uncolored do |color_enabled|
|
70
|
+
snippet = <<~TEST.strip
|
71
|
+
expect { raise 'boo' }.to raise_error('hell')
|
72
|
+
TEST
|
73
|
+
program = make_plain_test_program(
|
74
|
+
snippet,
|
75
|
+
color_enabled: color_enabled,
|
76
|
+
)
|
77
|
+
|
78
|
+
expected_output = build_expected_output(
|
79
|
+
color_enabled: color_enabled,
|
80
|
+
snippet: %|expect { raise 'boo' }.to raise_error('hell')|,
|
81
|
+
expectation: proc {
|
82
|
+
line do
|
83
|
+
plain "Expected raised exception "
|
84
|
+
beta %|#<RuntimeError "boo">|
|
85
|
+
plain " to match "
|
86
|
+
alpha %|#<Exception "hell">|
|
87
|
+
plain "."
|
88
|
+
end
|
89
|
+
},
|
90
|
+
)
|
91
|
+
|
92
|
+
expect(program).
|
93
|
+
to produce_output_when_run(expected_output).
|
94
|
+
in_color(color_enabled)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "produces the correct failure message when used in the negative" do
|
99
|
+
as_both_colored_and_uncolored do |color_enabled|
|
100
|
+
snippet = <<~TEST.strip
|
101
|
+
expect { raise 'boo' }.not_to raise_error('boo')
|
102
|
+
TEST
|
103
|
+
program = make_plain_test_program(
|
104
|
+
snippet,
|
105
|
+
color_enabled: color_enabled,
|
106
|
+
)
|
107
|
+
|
108
|
+
expected_output = build_expected_output(
|
109
|
+
color_enabled: color_enabled,
|
110
|
+
snippet: %|expect { raise 'boo' }.not_to raise_error('boo')|,
|
111
|
+
expectation: proc {
|
112
|
+
line do
|
113
|
+
plain "Expected raised exception "
|
114
|
+
beta %|#<RuntimeError "boo">|
|
115
|
+
plain " not to match "
|
116
|
+
alpha %|#<Exception "boo">|
|
117
|
+
plain "."
|
118
|
+
end
|
119
|
+
},
|
120
|
+
)
|
121
|
+
|
122
|
+
expect(program).
|
123
|
+
to produce_output_when_run(expected_output).
|
124
|
+
in_color(color_enabled)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "when the message is long" do
|
130
|
+
context "but contains no line breaks" do
|
131
|
+
it "produces the correct failure message when used in the positive" do
|
132
|
+
as_both_colored_and_uncolored do |color_enabled|
|
133
|
+
snippet = <<~TEST.strip
|
134
|
+
actual_message = "some really really really long message"
|
135
|
+
expected_message = "whatever"
|
136
|
+
expect { raise(actual_message) }.to raise_error(expected_message)
|
137
|
+
TEST
|
138
|
+
program = make_plain_test_program(
|
139
|
+
snippet,
|
140
|
+
color_enabled: color_enabled,
|
141
|
+
)
|
142
|
+
|
143
|
+
expected_output = build_expected_output(
|
144
|
+
color_enabled: color_enabled,
|
145
|
+
snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
|
146
|
+
newline_before_expectation: true,
|
147
|
+
expectation: proc {
|
148
|
+
line do
|
149
|
+
plain "Expected raised exception "
|
150
|
+
beta %|#<RuntimeError "some really really really long message">|
|
151
|
+
end
|
152
|
+
|
153
|
+
line do
|
154
|
+
plain " to match "
|
155
|
+
alpha %|#<Exception "whatever">|
|
156
|
+
end
|
157
|
+
},
|
158
|
+
)
|
159
|
+
|
160
|
+
expect(program).
|
161
|
+
to produce_output_when_run(expected_output).
|
162
|
+
in_color(color_enabled)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "produces the correct failure message when used in the negative" do
|
167
|
+
as_both_colored_and_uncolored do |color_enabled|
|
168
|
+
snippet = <<~TEST.strip
|
169
|
+
message = "some really long message"
|
170
|
+
expect { raise(message) }.not_to raise_error(message)
|
171
|
+
TEST
|
172
|
+
program = make_plain_test_program(
|
173
|
+
snippet,
|
174
|
+
color_enabled: color_enabled,
|
175
|
+
)
|
176
|
+
|
177
|
+
expected_output = build_expected_output(
|
178
|
+
color_enabled: color_enabled,
|
179
|
+
snippet: %|expect { raise(message) }.not_to raise_error(message)|,
|
180
|
+
newline_before_expectation: true,
|
181
|
+
expectation: proc {
|
182
|
+
line do
|
183
|
+
plain "Expected raised exception "
|
184
|
+
beta %|#<RuntimeError "some really long message">|
|
185
|
+
end
|
186
|
+
|
187
|
+
line do
|
188
|
+
plain " not to match "
|
189
|
+
alpha %|#<Exception "some really long message">|
|
190
|
+
end
|
191
|
+
},
|
192
|
+
)
|
193
|
+
|
194
|
+
expect(program).
|
195
|
+
to produce_output_when_run(expected_output).
|
196
|
+
in_color(color_enabled)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "but contains line breaks" do
|
202
|
+
it "produces the correct failure message when used in the positive" do
|
203
|
+
as_both_colored_and_uncolored do |color_enabled|
|
204
|
+
snippet = <<~TEST.strip
|
205
|
+
actual_message = <<\~MESSAGE.rstrip
|
206
|
+
This is fun
|
207
|
+
So is this
|
208
|
+
MESSAGE
|
209
|
+
expected_message = <<\~MESSAGE.rstrip
|
210
|
+
This is fun
|
211
|
+
And so is this
|
212
|
+
MESSAGE
|
213
|
+
expect { raise(actual_message) }.to raise_error(expected_message)
|
214
|
+
TEST
|
215
|
+
program = make_plain_test_program(
|
216
|
+
snippet,
|
217
|
+
color_enabled: color_enabled,
|
218
|
+
)
|
219
|
+
|
220
|
+
expected_output = build_expected_output(
|
221
|
+
color_enabled: color_enabled,
|
222
|
+
snippet: %|expect { raise(actual_message) }.to raise_error(expected_message)|,
|
223
|
+
expectation: proc {
|
224
|
+
line do
|
225
|
+
plain "Expected raised exception "
|
226
|
+
beta %|#<RuntimeError "This is fun\\nSo is this">|
|
227
|
+
end
|
228
|
+
|
229
|
+
line do
|
230
|
+
plain " to match "
|
231
|
+
alpha %|#<Exception "This is fun\\nAnd so is this">|
|
232
|
+
end
|
233
|
+
},
|
234
|
+
diff: proc {
|
235
|
+
plain_line %| This is fun\\n|
|
236
|
+
alpha_line %|- And so is this|
|
237
|
+
beta_line %|+ So is this|
|
238
|
+
},
|
239
|
+
)
|
240
|
+
|
241
|
+
expect(program).
|
242
|
+
to produce_output_when_run(expected_output).
|
243
|
+
in_color(color_enabled)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
it "produces the correct failure message when used in the negative" do
|
248
|
+
as_both_colored_and_uncolored do |color_enabled|
|
249
|
+
snippet = <<~TEST.strip
|
250
|
+
message = <<\~MESSAGE.rstrip
|
251
|
+
This is fun
|
252
|
+
So is this
|
253
|
+
MESSAGE
|
254
|
+
expect { raise(message) }.not_to raise_error(message)
|
255
|
+
TEST
|
256
|
+
program = make_plain_test_program(
|
257
|
+
snippet,
|
258
|
+
color_enabled: color_enabled,
|
259
|
+
)
|
260
|
+
|
261
|
+
expected_output = build_expected_output(
|
262
|
+
color_enabled: color_enabled,
|
263
|
+
snippet: %|expect { raise(message) }.not_to raise_error(message)|,
|
264
|
+
newline_before_expectation: true,
|
265
|
+
expectation: proc {
|
266
|
+
line do
|
267
|
+
plain "Expected raised exception "
|
268
|
+
beta %|#<RuntimeError "This is fun\\nSo is this">|
|
269
|
+
end
|
270
|
+
|
271
|
+
line do
|
272
|
+
plain " not to match "
|
273
|
+
alpha %|#<Exception "This is fun\\nSo is this">|
|
274
|
+
end
|
275
|
+
},
|
276
|
+
)
|
277
|
+
|
278
|
+
expect(program).
|
279
|
+
to produce_output_when_run(expected_output).
|
280
|
+
in_color(color_enabled)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context "with both an exception and a message" do
|
288
|
+
it "produces the correct failure message when used in the positive" do
|
289
|
+
as_both_colored_and_uncolored do |color_enabled|
|
290
|
+
snippet = <<~TEST.strip
|
291
|
+
block = -> { raise StandardError.new('a') }
|
292
|
+
expect(&block).to raise_error(RuntimeError, 'b')
|
293
|
+
TEST
|
294
|
+
program = make_plain_test_program(
|
295
|
+
snippet,
|
296
|
+
color_enabled: color_enabled,
|
297
|
+
)
|
298
|
+
|
299
|
+
expected_output = build_expected_output(
|
300
|
+
color_enabled: color_enabled,
|
301
|
+
snippet: %|expect(&block).to raise_error(RuntimeError, 'b')|,
|
302
|
+
expectation: proc {
|
303
|
+
line do
|
304
|
+
plain "Expected raised exception "
|
305
|
+
beta %|#<StandardError "a">|
|
306
|
+
plain " to match "
|
307
|
+
alpha %|#<RuntimeError "b">|
|
308
|
+
plain "."
|
309
|
+
end
|
310
|
+
},
|
311
|
+
)
|
312
|
+
|
313
|
+
expect(program).
|
314
|
+
to produce_output_when_run(expected_output).
|
315
|
+
in_color(color_enabled)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
it "produces the correct failure message when used in the negative" do
|
320
|
+
as_both_colored_and_uncolored do |color_enabled|
|
321
|
+
snippet = <<~TEST.strip
|
322
|
+
block = -> { raise StandardError.new('a') }
|
323
|
+
expect(&block).not_to raise_error(StandardError, 'a')
|
324
|
+
TEST
|
325
|
+
program = make_plain_test_program(
|
326
|
+
snippet,
|
327
|
+
color_enabled: color_enabled,
|
328
|
+
)
|
329
|
+
|
330
|
+
expected_output = build_expected_output(
|
331
|
+
color_enabled: color_enabled,
|
332
|
+
snippet: %|expect(&block).not_to raise_error(StandardError, 'a')|,
|
333
|
+
expectation: proc {
|
334
|
+
line do
|
335
|
+
plain "Expected raised exception "
|
336
|
+
beta %|#<StandardError "a">|
|
337
|
+
plain " not to match "
|
338
|
+
alpha %|#<StandardError "a">|
|
339
|
+
plain "."
|
340
|
+
end
|
341
|
+
},
|
342
|
+
)
|
343
|
+
|
344
|
+
expect(program).
|
345
|
+
to produce_output_when_run(expected_output).
|
346
|
+
in_color(color_enabled)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
@@ -0,0 +1,994 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
# TODO: Update coloring here
|
4
|
+
RSpec.describe "Integration with RSpec's #respond_to matcher", type: :integration do
|
5
|
+
context "without any qualifiers" do
|
6
|
+
context "when a few number of methods are specified" do
|
7
|
+
it "produces the correct failure message when used in the positive" do
|
8
|
+
as_both_colored_and_uncolored do |color_enabled|
|
9
|
+
snippet = %|expect(double).to respond_to(:foo)|
|
10
|
+
program = make_plain_test_program(
|
11
|
+
snippet,
|
12
|
+
color_enabled: color_enabled,
|
13
|
+
)
|
14
|
+
|
15
|
+
expected_output = build_expected_output(
|
16
|
+
color_enabled: color_enabled,
|
17
|
+
snippet: snippet,
|
18
|
+
expectation: proc {
|
19
|
+
line do
|
20
|
+
plain "Expected "
|
21
|
+
beta %|#<Double (anonymous)>|
|
22
|
+
plain " to respond to "
|
23
|
+
alpha %|:foo|
|
24
|
+
plain "."
|
25
|
+
end
|
26
|
+
},
|
27
|
+
)
|
28
|
+
|
29
|
+
expect(program).
|
30
|
+
to produce_output_when_run(expected_output).
|
31
|
+
in_color(color_enabled)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "produces the correct failure message when used in the negative" do
|
36
|
+
as_both_colored_and_uncolored do |color_enabled|
|
37
|
+
snippet = %|expect(double).not_to respond_to(:inspect)|
|
38
|
+
program = make_plain_test_program(
|
39
|
+
snippet,
|
40
|
+
color_enabled: color_enabled,
|
41
|
+
)
|
42
|
+
|
43
|
+
expected_output = build_expected_output(
|
44
|
+
color_enabled: color_enabled,
|
45
|
+
snippet: snippet,
|
46
|
+
expectation: proc {
|
47
|
+
line do
|
48
|
+
plain "Expected "
|
49
|
+
beta %|#<Double (anonymous)>|
|
50
|
+
plain " not to respond to "
|
51
|
+
alpha %|:inspect|
|
52
|
+
plain "."
|
53
|
+
end
|
54
|
+
},
|
55
|
+
)
|
56
|
+
|
57
|
+
expect(program).
|
58
|
+
to produce_output_when_run(expected_output).
|
59
|
+
in_color(color_enabled)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when a large number of methods are specified" do
|
65
|
+
it "produces the correct failure message when used in the positive" do
|
66
|
+
as_both_colored_and_uncolored do |color_enabled|
|
67
|
+
snippet = <<~TEST.strip
|
68
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :qux, :fizz, :buzz, :zing)
|
69
|
+
TEST
|
70
|
+
program = make_plain_test_program(
|
71
|
+
snippet,
|
72
|
+
color_enabled: color_enabled,
|
73
|
+
)
|
74
|
+
|
75
|
+
expected_output = build_expected_output(
|
76
|
+
color_enabled: color_enabled,
|
77
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :qux, :fizz, :buzz, :zing)|,
|
78
|
+
newline_before_expectation: true,
|
79
|
+
expectation: proc {
|
80
|
+
line do
|
81
|
+
plain " Expected "
|
82
|
+
beta %|#<Double :something_really_long>|
|
83
|
+
end
|
84
|
+
|
85
|
+
line do
|
86
|
+
plain "to respond to "
|
87
|
+
alpha %|:foo|
|
88
|
+
plain ", "
|
89
|
+
alpha %|:bar|
|
90
|
+
plain ", "
|
91
|
+
alpha %|:baz|
|
92
|
+
plain ", "
|
93
|
+
alpha %|:qux|
|
94
|
+
plain ", "
|
95
|
+
alpha %|:fizz|
|
96
|
+
plain ", "
|
97
|
+
alpha %|:buzz|
|
98
|
+
plain " and "
|
99
|
+
alpha %|:zing|
|
100
|
+
end
|
101
|
+
},
|
102
|
+
)
|
103
|
+
|
104
|
+
expect(program).
|
105
|
+
to produce_output_when_run(expected_output).
|
106
|
+
in_color(color_enabled)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "produces the correct failure message when used in the negative" do
|
111
|
+
as_both_colored_and_uncolored do |color_enabled|
|
112
|
+
snippet = <<~TEST.strip
|
113
|
+
class B
|
114
|
+
def some_really_long_method_and_stuff; end
|
115
|
+
def another_method_or_whatever; end
|
116
|
+
end
|
117
|
+
|
118
|
+
expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever)
|
119
|
+
TEST
|
120
|
+
program = make_plain_test_program(
|
121
|
+
snippet,
|
122
|
+
color_enabled: color_enabled,
|
123
|
+
)
|
124
|
+
|
125
|
+
expected_output = build_expected_output(
|
126
|
+
color_enabled: color_enabled,
|
127
|
+
snippet: %|expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever)|,
|
128
|
+
newline_before_expectation: true,
|
129
|
+
expectation: proc {
|
130
|
+
line do
|
131
|
+
plain " Expected "
|
132
|
+
beta %|#<B>|
|
133
|
+
end
|
134
|
+
|
135
|
+
line do
|
136
|
+
plain "not to respond to "
|
137
|
+
alpha %|:some_really_long_method_and_stuff|
|
138
|
+
plain " and "
|
139
|
+
alpha %|:another_method_or_whatever|
|
140
|
+
end
|
141
|
+
},
|
142
|
+
)
|
143
|
+
|
144
|
+
expect(program).
|
145
|
+
to produce_output_when_run(expected_output).
|
146
|
+
removing_object_ids.
|
147
|
+
in_color(color_enabled)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "qualified with #with + #arguments" do
|
154
|
+
context "when a few number of methods are specified when used in the positive" do
|
155
|
+
it "produces the correct failure message" do
|
156
|
+
as_both_colored_and_uncolored do |color_enabled|
|
157
|
+
snippet = <<~TEST.strip
|
158
|
+
expect(double).to respond_to(:foo).with(3).arguments
|
159
|
+
TEST
|
160
|
+
program = make_plain_test_program(
|
161
|
+
snippet,
|
162
|
+
color_enabled: color_enabled,
|
163
|
+
)
|
164
|
+
|
165
|
+
expected_output = build_expected_output(
|
166
|
+
color_enabled: color_enabled,
|
167
|
+
snippet: %|expect(double).to respond_to(:foo).with(3).arguments|,
|
168
|
+
expectation: proc {
|
169
|
+
line do
|
170
|
+
plain "Expected "
|
171
|
+
beta %|#<Double (anonymous)>|
|
172
|
+
plain " to respond to "
|
173
|
+
alpha %|:foo|
|
174
|
+
plain " with "
|
175
|
+
alpha %|3|
|
176
|
+
plain " arguments."
|
177
|
+
end
|
178
|
+
},
|
179
|
+
)
|
180
|
+
|
181
|
+
expect(program).
|
182
|
+
to produce_output_when_run(expected_output).
|
183
|
+
in_color(color_enabled)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it "produces the correct failure message when used in the negative" do
|
188
|
+
as_both_colored_and_uncolored do |color_enabled|
|
189
|
+
snippet = <<~TEST.strip
|
190
|
+
class B
|
191
|
+
def foo(bar, baz, qux); end
|
192
|
+
end
|
193
|
+
|
194
|
+
expect(B.new).not_to respond_to(:foo).with(3).arguments
|
195
|
+
TEST
|
196
|
+
program = make_plain_test_program(
|
197
|
+
snippet,
|
198
|
+
color_enabled: color_enabled,
|
199
|
+
)
|
200
|
+
|
201
|
+
expected_output = build_expected_output(
|
202
|
+
color_enabled: color_enabled,
|
203
|
+
snippet: %|expect(B.new).not_to respond_to(:foo).with(3).arguments|,
|
204
|
+
expectation: proc {
|
205
|
+
line do
|
206
|
+
plain "Expected "
|
207
|
+
beta %|#<B>|
|
208
|
+
plain " not to respond to "
|
209
|
+
alpha %|:foo|
|
210
|
+
plain " with "
|
211
|
+
alpha %|3|
|
212
|
+
plain " arguments."
|
213
|
+
end
|
214
|
+
},
|
215
|
+
)
|
216
|
+
|
217
|
+
expect(program).
|
218
|
+
to produce_output_when_run(expected_output).
|
219
|
+
removing_object_ids.
|
220
|
+
in_color(color_enabled)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context "when a large number of methods are specified" do
|
226
|
+
it "produces the correct failure message when used in the positive" do
|
227
|
+
as_both_colored_and_uncolored do |color_enabled|
|
228
|
+
snippet = <<~TEST.strip
|
229
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :fizz, :buzz).with(3).arguments
|
230
|
+
TEST
|
231
|
+
program = make_plain_test_program(
|
232
|
+
snippet,
|
233
|
+
color_enabled: color_enabled,
|
234
|
+
)
|
235
|
+
|
236
|
+
expected_output = build_expected_output(
|
237
|
+
color_enabled: color_enabled,
|
238
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :fizz, :buzz).with(3).arguments|,
|
239
|
+
newline_before_expectation: true,
|
240
|
+
expectation: proc {
|
241
|
+
line do
|
242
|
+
plain " Expected "
|
243
|
+
beta %|#<Double :something_really_long>|
|
244
|
+
end
|
245
|
+
|
246
|
+
line do
|
247
|
+
plain "to respond to "
|
248
|
+
alpha %|:foo|
|
249
|
+
plain ", "
|
250
|
+
alpha %|:bar|
|
251
|
+
plain ", "
|
252
|
+
alpha %|:baz|
|
253
|
+
plain ", "
|
254
|
+
alpha %|:fizz|
|
255
|
+
plain " and "
|
256
|
+
alpha %|:buzz|
|
257
|
+
plain " with "
|
258
|
+
alpha %|3|
|
259
|
+
plain " arguments"
|
260
|
+
end
|
261
|
+
},
|
262
|
+
)
|
263
|
+
|
264
|
+
expect(program).
|
265
|
+
to produce_output_when_run(expected_output).
|
266
|
+
in_color(color_enabled)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
it "produces the correct failure message when used in the negative" do
|
271
|
+
as_both_colored_and_uncolored do |color_enabled|
|
272
|
+
snippet = <<~TEST.strip
|
273
|
+
class B
|
274
|
+
def some_really_long_method_and_stuff(foo, bar, baz); end
|
275
|
+
def another_method_or_whatever(foo, bar, baz); end
|
276
|
+
end
|
277
|
+
|
278
|
+
expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with(3).arguments
|
279
|
+
TEST
|
280
|
+
program = make_plain_test_program(
|
281
|
+
snippet,
|
282
|
+
color_enabled: color_enabled,
|
283
|
+
)
|
284
|
+
|
285
|
+
expected_output = build_expected_output(
|
286
|
+
color_enabled: color_enabled,
|
287
|
+
snippet: %|expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with(3).arguments|,
|
288
|
+
newline_before_expectation: true,
|
289
|
+
expectation: proc {
|
290
|
+
line do
|
291
|
+
plain " Expected "
|
292
|
+
beta %|#<B>|
|
293
|
+
end
|
294
|
+
|
295
|
+
line do
|
296
|
+
plain "not to respond to "
|
297
|
+
alpha %|:some_really_long_method_and_stuff|
|
298
|
+
plain " and "
|
299
|
+
alpha %|:another_method_or_whatever|
|
300
|
+
plain " with "
|
301
|
+
alpha %|3|
|
302
|
+
plain " arguments"
|
303
|
+
end
|
304
|
+
},
|
305
|
+
)
|
306
|
+
|
307
|
+
expect(program).
|
308
|
+
to produce_output_when_run(expected_output).
|
309
|
+
removing_object_ids.
|
310
|
+
in_color(color_enabled)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
context "qualified with #with_keywords" do
|
317
|
+
context "when a few number of methods are specified" do
|
318
|
+
it "produces the correct failure message when used in the positive" do
|
319
|
+
as_both_colored_and_uncolored do |color_enabled|
|
320
|
+
snippet = <<~TEST.strip
|
321
|
+
expect(double).to respond_to(:foo).with_keywords(:bar)
|
322
|
+
TEST
|
323
|
+
program = make_plain_test_program(
|
324
|
+
snippet,
|
325
|
+
color_enabled: color_enabled,
|
326
|
+
)
|
327
|
+
|
328
|
+
expected_output = build_expected_output(
|
329
|
+
color_enabled: color_enabled,
|
330
|
+
snippet: %|expect(double).to respond_to(:foo).with_keywords(:bar)|,
|
331
|
+
expectation: proc {
|
332
|
+
line do
|
333
|
+
plain "Expected "
|
334
|
+
beta %|#<Double (anonymous)>|
|
335
|
+
plain " to respond to "
|
336
|
+
alpha %|:foo|
|
337
|
+
plain " with keyword "
|
338
|
+
alpha %|:bar|
|
339
|
+
plain "."
|
340
|
+
end
|
341
|
+
},
|
342
|
+
)
|
343
|
+
|
344
|
+
expect(program).
|
345
|
+
to produce_output_when_run(expected_output).
|
346
|
+
in_color(color_enabled)
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
it "produces the correct failure message when used in the negative" do
|
351
|
+
as_both_colored_and_uncolored do |color_enabled|
|
352
|
+
snippet = <<~TEST.strip
|
353
|
+
class B
|
354
|
+
def foo(bar:); end
|
355
|
+
end
|
356
|
+
|
357
|
+
expect(B.new).not_to respond_to(:foo).with_keywords(:bar)
|
358
|
+
TEST
|
359
|
+
program = make_plain_test_program(
|
360
|
+
snippet,
|
361
|
+
color_enabled: color_enabled,
|
362
|
+
)
|
363
|
+
|
364
|
+
expected_output = build_expected_output(
|
365
|
+
color_enabled: color_enabled,
|
366
|
+
snippet: %|expect(B.new).not_to respond_to(:foo).with_keywords(:bar)|,
|
367
|
+
expectation: proc {
|
368
|
+
line do
|
369
|
+
plain "Expected "
|
370
|
+
beta %|#<B>|
|
371
|
+
plain " not to respond to "
|
372
|
+
alpha %|:foo|
|
373
|
+
plain " with keyword "
|
374
|
+
alpha %|:bar|
|
375
|
+
plain "."
|
376
|
+
end
|
377
|
+
},
|
378
|
+
)
|
379
|
+
|
380
|
+
expect(program).
|
381
|
+
to produce_output_when_run(expected_output).
|
382
|
+
removing_object_ids.
|
383
|
+
in_color(color_enabled)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
context "when a large number of methods are specified" do
|
389
|
+
it "produces the correct failure message when used in the positive" do
|
390
|
+
as_both_colored_and_uncolored do |color_enabled|
|
391
|
+
snippet = <<~TEST.strip
|
392
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :fizz, :buzz).with_keywords(:qux, :blargh)
|
393
|
+
TEST
|
394
|
+
program = make_plain_test_program(
|
395
|
+
snippet,
|
396
|
+
color_enabled: color_enabled,
|
397
|
+
)
|
398
|
+
|
399
|
+
expected_output = build_expected_output(
|
400
|
+
color_enabled: color_enabled,
|
401
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :fizz, :buzz).with_keywords(:qux, :blargh)|,
|
402
|
+
newline_before_expectation: true,
|
403
|
+
expectation: proc {
|
404
|
+
line do
|
405
|
+
plain " Expected "
|
406
|
+
beta %|#<Double :something_really_long>|
|
407
|
+
end
|
408
|
+
|
409
|
+
line do
|
410
|
+
plain "to respond to "
|
411
|
+
alpha %|:foo|
|
412
|
+
plain ", "
|
413
|
+
alpha %|:bar|
|
414
|
+
plain ", "
|
415
|
+
alpha %|:baz|
|
416
|
+
plain ", "
|
417
|
+
alpha %|:fizz|
|
418
|
+
plain " and "
|
419
|
+
alpha %|:buzz|
|
420
|
+
plain " with keywords "
|
421
|
+
alpha %|:qux|
|
422
|
+
plain " and "
|
423
|
+
alpha %|:blargh|
|
424
|
+
end
|
425
|
+
},
|
426
|
+
)
|
427
|
+
|
428
|
+
expect(program).
|
429
|
+
to produce_output_when_run(expected_output).
|
430
|
+
in_color(color_enabled)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
it "produces the correct failure message when used in the negative" do
|
435
|
+
as_both_colored_and_uncolored do |color_enabled|
|
436
|
+
snippet = <<~TEST.strip
|
437
|
+
class B
|
438
|
+
def some_really_long_method_and_stuff(foo:, bar:); end
|
439
|
+
def another_method_or_whatever(foo:, bar:); end
|
440
|
+
end
|
441
|
+
|
442
|
+
expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_keywords(:foo, :bar)
|
443
|
+
TEST
|
444
|
+
program = make_plain_test_program(
|
445
|
+
snippet,
|
446
|
+
color_enabled: color_enabled,
|
447
|
+
)
|
448
|
+
|
449
|
+
expected_output = build_expected_output(
|
450
|
+
color_enabled: color_enabled,
|
451
|
+
snippet: %|expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_keywords(:foo, :bar)|,
|
452
|
+
newline_before_expectation: true,
|
453
|
+
expectation: proc {
|
454
|
+
line do
|
455
|
+
plain " Expected "
|
456
|
+
beta %|#<B>|
|
457
|
+
end
|
458
|
+
|
459
|
+
line do
|
460
|
+
plain "not to respond to "
|
461
|
+
alpha %|:some_really_long_method_and_stuff|
|
462
|
+
plain " and "
|
463
|
+
alpha %|:another_method_or_whatever|
|
464
|
+
plain " with keywords "
|
465
|
+
alpha %|:foo|
|
466
|
+
plain " and "
|
467
|
+
alpha %|:bar|
|
468
|
+
end
|
469
|
+
},
|
470
|
+
)
|
471
|
+
|
472
|
+
expect(program).
|
473
|
+
to produce_output_when_run(expected_output).
|
474
|
+
removing_object_ids.
|
475
|
+
in_color(color_enabled)
|
476
|
+
end
|
477
|
+
end
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
context "qualified with #with_any_keywords" do
|
482
|
+
context "when a few number of methods are specified" do
|
483
|
+
it "produces the correct failure message when used in the positive" do
|
484
|
+
as_both_colored_and_uncolored do |color_enabled|
|
485
|
+
snippet = <<~TEST.strip
|
486
|
+
expect(double).to respond_to(:foo).with_any_keywords
|
487
|
+
TEST
|
488
|
+
program = make_plain_test_program(
|
489
|
+
snippet,
|
490
|
+
color_enabled: color_enabled,
|
491
|
+
)
|
492
|
+
|
493
|
+
expected_output = build_expected_output(
|
494
|
+
color_enabled: color_enabled,
|
495
|
+
snippet: %|expect(double).to respond_to(:foo).with_any_keywords|,
|
496
|
+
expectation: proc {
|
497
|
+
line do
|
498
|
+
plain "Expected "
|
499
|
+
beta %|#<Double (anonymous)>|
|
500
|
+
plain " to respond to "
|
501
|
+
alpha %|:foo|
|
502
|
+
plain " with "
|
503
|
+
alpha %|any|
|
504
|
+
plain " keywords."
|
505
|
+
end
|
506
|
+
},
|
507
|
+
)
|
508
|
+
|
509
|
+
expect(program).
|
510
|
+
to produce_output_when_run(expected_output).
|
511
|
+
in_color(color_enabled)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
it "produces the correct failure message when used in the negative" do
|
516
|
+
as_both_colored_and_uncolored do |color_enabled|
|
517
|
+
snippet = <<~TEST.strip
|
518
|
+
class B
|
519
|
+
def foo(**options); end
|
520
|
+
end
|
521
|
+
|
522
|
+
expect(B.new).not_to respond_to(:foo).with_any_keywords
|
523
|
+
TEST
|
524
|
+
program = make_plain_test_program(
|
525
|
+
snippet,
|
526
|
+
color_enabled: color_enabled,
|
527
|
+
)
|
528
|
+
|
529
|
+
expected_output = build_expected_output(
|
530
|
+
color_enabled: color_enabled,
|
531
|
+
snippet: %|expect(B.new).not_to respond_to(:foo).with_any_keywords|,
|
532
|
+
expectation: proc {
|
533
|
+
line do
|
534
|
+
plain "Expected "
|
535
|
+
beta %|#<B>|
|
536
|
+
plain " not to respond to "
|
537
|
+
alpha %|:foo|
|
538
|
+
plain " with "
|
539
|
+
alpha %|any|
|
540
|
+
plain " keywords."
|
541
|
+
end
|
542
|
+
},
|
543
|
+
)
|
544
|
+
|
545
|
+
expect(program).
|
546
|
+
to produce_output_when_run(expected_output).
|
547
|
+
removing_object_ids.
|
548
|
+
in_color(color_enabled)
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
553
|
+
context "when a large number of methods are specified" do
|
554
|
+
it "produces the correct failure message when used in the positive" do
|
555
|
+
as_both_colored_and_uncolored do |color_enabled|
|
556
|
+
snippet = <<~TEST.strip
|
557
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :qux, :fizz, :buzz).with_any_keywords
|
558
|
+
TEST
|
559
|
+
program = make_plain_test_program(
|
560
|
+
snippet,
|
561
|
+
color_enabled: color_enabled,
|
562
|
+
)
|
563
|
+
|
564
|
+
expected_output = build_expected_output(
|
565
|
+
color_enabled: color_enabled,
|
566
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz, :qux, :fizz, :buzz).with_any_keywords|,
|
567
|
+
newline_before_expectation: true,
|
568
|
+
expectation: proc {
|
569
|
+
line do
|
570
|
+
plain " Expected "
|
571
|
+
beta %|#<Double :something_really_long>|
|
572
|
+
end
|
573
|
+
|
574
|
+
line do
|
575
|
+
plain "to respond to "
|
576
|
+
alpha %|:foo|
|
577
|
+
plain ", "
|
578
|
+
alpha %|:bar|
|
579
|
+
plain ", "
|
580
|
+
alpha %|:baz|
|
581
|
+
plain ", "
|
582
|
+
alpha %|:qux|
|
583
|
+
plain ", "
|
584
|
+
alpha %|:fizz|
|
585
|
+
plain " and "
|
586
|
+
alpha %|:buzz|
|
587
|
+
plain " with "
|
588
|
+
alpha %|any|
|
589
|
+
plain " keywords "
|
590
|
+
end
|
591
|
+
},
|
592
|
+
)
|
593
|
+
|
594
|
+
expect(program).
|
595
|
+
to produce_output_when_run(expected_output).
|
596
|
+
in_color(color_enabled)
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
it "produces the correct failure message when used in the negative" do
|
601
|
+
as_both_colored_and_uncolored do |color_enabled|
|
602
|
+
snippet = <<~TEST.strip
|
603
|
+
class B
|
604
|
+
def some_really_long_method_and_stuff(**options); end
|
605
|
+
def another_method_or_whatever(**options); end
|
606
|
+
end
|
607
|
+
|
608
|
+
expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_any_keywords
|
609
|
+
TEST
|
610
|
+
program = make_plain_test_program(
|
611
|
+
snippet,
|
612
|
+
color_enabled: color_enabled,
|
613
|
+
)
|
614
|
+
|
615
|
+
expected_output = build_expected_output(
|
616
|
+
color_enabled: color_enabled,
|
617
|
+
snippet: %|expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_any_keywords|,
|
618
|
+
newline_before_expectation: true,
|
619
|
+
expectation: proc {
|
620
|
+
line do
|
621
|
+
plain " Expected "
|
622
|
+
beta %|#<B>|
|
623
|
+
end
|
624
|
+
|
625
|
+
line do
|
626
|
+
plain "not to respond to "
|
627
|
+
alpha %|:some_really_long_method_and_stuff|
|
628
|
+
plain " and "
|
629
|
+
alpha %|:another_method_or_whatever|
|
630
|
+
plain " with "
|
631
|
+
alpha %|any|
|
632
|
+
plain " keywords "
|
633
|
+
end
|
634
|
+
},
|
635
|
+
)
|
636
|
+
|
637
|
+
expect(program).
|
638
|
+
to produce_output_when_run(expected_output).
|
639
|
+
removing_object_ids.
|
640
|
+
in_color(color_enabled)
|
641
|
+
end
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
|
646
|
+
context "qualified with #with_unlimited_arguments" do
|
647
|
+
context "when a few number of methods are specified" do
|
648
|
+
it "produces the correct failure message when used in the positive" do
|
649
|
+
as_both_colored_and_uncolored do |color_enabled|
|
650
|
+
snippet = <<~TEST.strip
|
651
|
+
expect(double).to respond_to(:foo).with_unlimited_arguments
|
652
|
+
TEST
|
653
|
+
program = make_plain_test_program(
|
654
|
+
snippet,
|
655
|
+
color_enabled: color_enabled,
|
656
|
+
)
|
657
|
+
|
658
|
+
expected_output = build_expected_output(
|
659
|
+
color_enabled: color_enabled,
|
660
|
+
snippet: %|expect(double).to respond_to(:foo).with_unlimited_arguments|,
|
661
|
+
expectation: proc {
|
662
|
+
line do
|
663
|
+
plain "Expected "
|
664
|
+
beta %|#<Double (anonymous)>|
|
665
|
+
plain " to respond to "
|
666
|
+
alpha %|:foo|
|
667
|
+
plain " with "
|
668
|
+
alpha %|unlimited|
|
669
|
+
plain " arguments."
|
670
|
+
end
|
671
|
+
},
|
672
|
+
)
|
673
|
+
|
674
|
+
expect(program).
|
675
|
+
to produce_output_when_run(expected_output).
|
676
|
+
in_color(color_enabled)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
it "produces the correct failure message when used in the negative" do
|
681
|
+
as_both_colored_and_uncolored do |color_enabled|
|
682
|
+
snippet = <<~TEST.strip
|
683
|
+
class B
|
684
|
+
def foo(*args); end
|
685
|
+
end
|
686
|
+
|
687
|
+
expect(B.new).not_to respond_to(:foo).with_unlimited_arguments
|
688
|
+
TEST
|
689
|
+
program = make_plain_test_program(
|
690
|
+
snippet,
|
691
|
+
color_enabled: color_enabled,
|
692
|
+
)
|
693
|
+
|
694
|
+
expected_output = build_expected_output(
|
695
|
+
color_enabled: color_enabled,
|
696
|
+
snippet: %|expect(B.new).not_to respond_to(:foo).with_unlimited_arguments|,
|
697
|
+
expectation: proc {
|
698
|
+
line do
|
699
|
+
plain "Expected "
|
700
|
+
beta %|#<B>|
|
701
|
+
plain " not to respond to "
|
702
|
+
alpha %|:foo|
|
703
|
+
plain " with "
|
704
|
+
alpha %|unlimited|
|
705
|
+
plain " arguments."
|
706
|
+
end
|
707
|
+
},
|
708
|
+
)
|
709
|
+
|
710
|
+
expect(program).
|
711
|
+
to produce_output_when_run(expected_output).
|
712
|
+
removing_object_ids.
|
713
|
+
in_color(color_enabled)
|
714
|
+
end
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
context "when a large number of methods are specified" do
|
719
|
+
it "produces the correct failure message when used in the positive" do
|
720
|
+
as_both_colored_and_uncolored do |color_enabled|
|
721
|
+
snippet = <<~TEST.strip
|
722
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_unlimited_arguments
|
723
|
+
TEST
|
724
|
+
program = make_plain_test_program(
|
725
|
+
snippet,
|
726
|
+
color_enabled: color_enabled,
|
727
|
+
)
|
728
|
+
|
729
|
+
expected_output = build_expected_output(
|
730
|
+
color_enabled: color_enabled,
|
731
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_unlimited_arguments|,
|
732
|
+
newline_before_expectation: true,
|
733
|
+
expectation: proc {
|
734
|
+
line do
|
735
|
+
plain " Expected "
|
736
|
+
beta %|#<Double :something_really_long>|
|
737
|
+
end
|
738
|
+
|
739
|
+
line do
|
740
|
+
plain "to respond to "
|
741
|
+
alpha %|:foo|
|
742
|
+
plain ", "
|
743
|
+
alpha %|:bar|
|
744
|
+
plain " and "
|
745
|
+
alpha %|:baz|
|
746
|
+
plain " with "
|
747
|
+
alpha %|unlimited|
|
748
|
+
plain " arguments"
|
749
|
+
end
|
750
|
+
},
|
751
|
+
)
|
752
|
+
|
753
|
+
expect(program).
|
754
|
+
to produce_output_when_run(expected_output).
|
755
|
+
in_color(color_enabled)
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
it "produces the correct failure message when used in the negative" do
|
760
|
+
as_both_colored_and_uncolored do |color_enabled|
|
761
|
+
snippet = <<~TEST.strip
|
762
|
+
class B
|
763
|
+
def some_really_long_method_and_stuff(*args); end
|
764
|
+
def another_method_or_whatever(*args); end
|
765
|
+
end
|
766
|
+
|
767
|
+
expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_unlimited_arguments
|
768
|
+
TEST
|
769
|
+
program = make_plain_test_program(
|
770
|
+
snippet,
|
771
|
+
color_enabled: color_enabled,
|
772
|
+
)
|
773
|
+
|
774
|
+
expected_output = build_expected_output(
|
775
|
+
color_enabled: color_enabled,
|
776
|
+
snippet: %|expect(B.new).not_to respond_to(:some_really_long_method_and_stuff, :another_method_or_whatever).with_unlimited_arguments|,
|
777
|
+
newline_before_expectation: true,
|
778
|
+
expectation: proc {
|
779
|
+
line do
|
780
|
+
plain " Expected "
|
781
|
+
beta %|#<B>|
|
782
|
+
end
|
783
|
+
|
784
|
+
line do
|
785
|
+
plain "not to respond to "
|
786
|
+
alpha %|:some_really_long_method_and_stuff|
|
787
|
+
plain " and "
|
788
|
+
alpha %|:another_method_or_whatever|
|
789
|
+
plain " with "
|
790
|
+
alpha %|unlimited|
|
791
|
+
plain " arguments"
|
792
|
+
end
|
793
|
+
},
|
794
|
+
)
|
795
|
+
|
796
|
+
expect(program).
|
797
|
+
to produce_output_when_run(expected_output).
|
798
|
+
removing_object_ids.
|
799
|
+
in_color(color_enabled)
|
800
|
+
end
|
801
|
+
end
|
802
|
+
end
|
803
|
+
end
|
804
|
+
|
805
|
+
context "qualified with #with_any_keywords + #with_unlimited_arguments" do
|
806
|
+
it "produces the correct failure message when used in the positive" do
|
807
|
+
as_both_colored_and_uncolored do |color_enabled|
|
808
|
+
snippet = <<~TEST.strip
|
809
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_any_keywords.with_unlimited_arguments
|
810
|
+
TEST
|
811
|
+
program = make_plain_test_program(
|
812
|
+
snippet,
|
813
|
+
color_enabled: color_enabled,
|
814
|
+
)
|
815
|
+
|
816
|
+
expected_output = build_expected_output(
|
817
|
+
color_enabled: color_enabled,
|
818
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_any_keywords.with_unlimited_arguments|,
|
819
|
+
newline_before_expectation: true,
|
820
|
+
expectation: proc {
|
821
|
+
line do
|
822
|
+
plain " Expected "
|
823
|
+
beta %|#<Double :something_really_long>|
|
824
|
+
end
|
825
|
+
|
826
|
+
line do
|
827
|
+
plain "to respond to "
|
828
|
+
alpha %|:foo|
|
829
|
+
plain ", "
|
830
|
+
alpha %|:bar|
|
831
|
+
plain " and "
|
832
|
+
alpha %|:baz|
|
833
|
+
plain " with "
|
834
|
+
alpha %|any|
|
835
|
+
plain " keywords and "
|
836
|
+
alpha %|unlimited|
|
837
|
+
plain " arguments"
|
838
|
+
end
|
839
|
+
},
|
840
|
+
)
|
841
|
+
|
842
|
+
expect(program).
|
843
|
+
to produce_output_when_run(expected_output).
|
844
|
+
in_color(color_enabled)
|
845
|
+
end
|
846
|
+
end
|
847
|
+
|
848
|
+
it "produces the correct failure message when used in the negative" do
|
849
|
+
as_both_colored_and_uncolored do |color_enabled|
|
850
|
+
snippet = <<~TEST.strip
|
851
|
+
class B
|
852
|
+
def foo(*args, **options); end
|
853
|
+
def bar(*args, **options); end
|
854
|
+
def baz(*args, **options); end
|
855
|
+
end
|
856
|
+
|
857
|
+
expect(B.new).not_to respond_to(:foo, :bar, :baz).with_any_keywords.with_unlimited_arguments
|
858
|
+
TEST
|
859
|
+
program = make_plain_test_program(
|
860
|
+
snippet,
|
861
|
+
color_enabled: color_enabled,
|
862
|
+
)
|
863
|
+
|
864
|
+
expected_output = build_expected_output(
|
865
|
+
color_enabled: color_enabled,
|
866
|
+
snippet: %|expect(B.new).not_to respond_to(:foo, :bar, :baz).with_any_keywords.with_unlimited_arguments|,
|
867
|
+
newline_before_expectation: true,
|
868
|
+
expectation: proc {
|
869
|
+
line do
|
870
|
+
plain " Expected "
|
871
|
+
beta %|#<B>|
|
872
|
+
end
|
873
|
+
|
874
|
+
line do
|
875
|
+
plain "not to respond to "
|
876
|
+
alpha %|:foo|
|
877
|
+
plain ", "
|
878
|
+
alpha %|:bar|
|
879
|
+
plain " and "
|
880
|
+
alpha %|:baz|
|
881
|
+
plain " with "
|
882
|
+
alpha %|any|
|
883
|
+
plain " keywords and "
|
884
|
+
alpha %|unlimited|
|
885
|
+
plain " arguments"
|
886
|
+
end
|
887
|
+
},
|
888
|
+
)
|
889
|
+
|
890
|
+
expect(program).
|
891
|
+
to produce_output_when_run(expected_output).
|
892
|
+
removing_object_ids.
|
893
|
+
in_color(color_enabled)
|
894
|
+
end
|
895
|
+
end
|
896
|
+
end
|
897
|
+
|
898
|
+
context "qualified with #with_keywords + #with_unlimited_arguments" do
|
899
|
+
it "produces the correct failure message when used in the positive" do
|
900
|
+
as_both_colored_and_uncolored do |color_enabled|
|
901
|
+
snippet = <<~TEST.strip
|
902
|
+
expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_keywords(:qux, :blargh).with_unlimited_arguments
|
903
|
+
TEST
|
904
|
+
program = make_plain_test_program(
|
905
|
+
snippet,
|
906
|
+
color_enabled: color_enabled,
|
907
|
+
)
|
908
|
+
|
909
|
+
expected_output = build_expected_output(
|
910
|
+
color_enabled: color_enabled,
|
911
|
+
snippet: %|expect(double(:something_really_long)).to respond_to(:foo, :bar, :baz).with_keywords(:qux, :blargh).with_unlimited_arguments|,
|
912
|
+
newline_before_expectation: true,
|
913
|
+
expectation: proc {
|
914
|
+
line do
|
915
|
+
plain " Expected "
|
916
|
+
beta %|#<Double :something_really_long>|
|
917
|
+
end
|
918
|
+
|
919
|
+
line do
|
920
|
+
plain "to respond to "
|
921
|
+
alpha %|:foo|
|
922
|
+
plain ", "
|
923
|
+
alpha %|:bar|
|
924
|
+
plain " and "
|
925
|
+
alpha %|:baz|
|
926
|
+
plain " with keywords "
|
927
|
+
alpha %|:qux|
|
928
|
+
plain " and "
|
929
|
+
alpha %|:blargh|
|
930
|
+
plain " and "
|
931
|
+
alpha %|unlimited|
|
932
|
+
plain " arguments"
|
933
|
+
end
|
934
|
+
},
|
935
|
+
)
|
936
|
+
|
937
|
+
expect(program).
|
938
|
+
to produce_output_when_run(expected_output).
|
939
|
+
in_color(color_enabled)
|
940
|
+
end
|
941
|
+
end
|
942
|
+
|
943
|
+
it "produces the correct failure message when used in the negative" do
|
944
|
+
as_both_colored_and_uncolored do |color_enabled|
|
945
|
+
snippet = <<~TEST.strip
|
946
|
+
class B
|
947
|
+
def foo(*args, qux:, blargh:); end
|
948
|
+
def bar(*args, qux:, blargh:); end
|
949
|
+
def baz(*args, qux:, blargh:); end
|
950
|
+
end
|
951
|
+
|
952
|
+
expect(B.new).not_to respond_to(:foo, :bar, :baz).with_keywords(:qux, :blargh).with_unlimited_arguments
|
953
|
+
TEST
|
954
|
+
program = make_plain_test_program(
|
955
|
+
snippet,
|
956
|
+
color_enabled: color_enabled,
|
957
|
+
)
|
958
|
+
|
959
|
+
expected_output = build_expected_output(
|
960
|
+
color_enabled: color_enabled,
|
961
|
+
snippet: %|expect(B.new).not_to respond_to(:foo, :bar, :baz).with_keywords(:qux, :blargh).with_unlimited_arguments|,
|
962
|
+
newline_before_expectation: true,
|
963
|
+
expectation: proc {
|
964
|
+
line do
|
965
|
+
plain " Expected "
|
966
|
+
beta %|#<B>|
|
967
|
+
end
|
968
|
+
|
969
|
+
line do
|
970
|
+
plain "not to respond to "
|
971
|
+
alpha %|:foo|
|
972
|
+
plain ", "
|
973
|
+
alpha %|:bar|
|
974
|
+
plain " and "
|
975
|
+
alpha %|:baz|
|
976
|
+
plain " with keywords "
|
977
|
+
alpha %|:qux|
|
978
|
+
plain " and "
|
979
|
+
alpha %|:blargh|
|
980
|
+
plain " and "
|
981
|
+
alpha %|unlimited|
|
982
|
+
plain " arguments"
|
983
|
+
end
|
984
|
+
},
|
985
|
+
)
|
986
|
+
|
987
|
+
expect(program).
|
988
|
+
to produce_output_when_run(expected_output).
|
989
|
+
removing_object_ids.
|
990
|
+
in_color(color_enabled)
|
991
|
+
end
|
992
|
+
end
|
993
|
+
end
|
994
|
+
end
|