rubocop-rspec 1.35.0 → 1.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/config/default.yml +11 -0
- data/lib/rubocop/cop/rspec/capybara/current_path_expectation.rb +16 -0
- data/lib/rubocop/cop/rspec/context_method.rb +53 -0
- data/lib/rubocop/cop/rspec/describe_class.rb +7 -10
- data/lib/rubocop/cop/rspec/described_class.rb +29 -1
- data/lib/rubocop/cop/rspec/empty_line_after_example.rb +87 -0
- data/lib/rubocop/cop/rspec/example_wording.rb +28 -12
- data/lib/rubocop/cop/rspec/expect_change.rb +8 -8
- data/lib/rubocop/cop/rspec/factory_bot/attribute_defined_statically.rb +2 -9
- data/lib/rubocop/cop/rspec/focus.rb +5 -10
- data/lib/rubocop/cop/rspec/instance_variable.rb +2 -1
- data/lib/rubocop/cop/rspec/multiple_expectations.rb +13 -21
- data/lib/rubocop/cop/rspec/pending.rb +19 -25
- data/lib/rubocop/cop/rspec_cops.rb +2 -0
- data/lib/rubocop/rspec/version.rb +1 -1
- metadata +7 -198
- data/Gemfile +0 -11
- data/Rakefile +0 -87
- data/rubocop-rspec.gemspec +0 -49
- data/spec/project/changelog_spec.rb +0 -76
- data/spec/project/default_config_spec.rb +0 -76
- data/spec/project/project_requires_spec.rb +0 -20
- data/spec/rubocop/cop/rspec/align_left_let_brace_spec.rb +0 -51
- data/spec/rubocop/cop/rspec/align_right_let_brace_spec.rb +0 -51
- data/spec/rubocop/cop/rspec/any_instance_spec.rb +0 -32
- data/spec/rubocop/cop/rspec/around_block_spec.rb +0 -121
- data/spec/rubocop/cop/rspec/be_eql_spec.rb +0 -81
- data/spec/rubocop/cop/rspec/be_spec.rb +0 -35
- data/spec/rubocop/cop/rspec/before_after_all_spec.rb +0 -52
- data/spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb +0 -65
- data/spec/rubocop/cop/rspec/capybara/feature_methods_spec.rb +0 -130
- data/spec/rubocop/cop/rspec/context_wording_spec.rb +0 -94
- data/spec/rubocop/cop/rspec/cop_spec.rb +0 -95
- data/spec/rubocop/cop/rspec/describe_class_spec.rb +0 -168
- data/spec/rubocop/cop/rspec/describe_method_spec.rb +0 -34
- data/spec/rubocop/cop/rspec/describe_symbol_spec.rb +0 -44
- data/spec/rubocop/cop/rspec/described_class_spec.rb +0 -352
- data/spec/rubocop/cop/rspec/dialect_spec.rb +0 -78
- data/spec/rubocop/cop/rspec/empty_example_group_spec.rb +0 -93
- data/spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb +0 -121
- data/spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb +0 -239
- data/spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb +0 -133
- data/spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb +0 -94
- data/spec/rubocop/cop/rspec/example_length_spec.rb +0 -78
- data/spec/rubocop/cop/rspec/example_without_description_spec.rb +0 -92
- data/spec/rubocop/cop/rspec/example_wording_spec.rb +0 -173
- data/spec/rubocop/cop/rspec/expect_actual_spec.rb +0 -150
- data/spec/rubocop/cop/rspec/expect_change_spec.rb +0 -86
- data/spec/rubocop/cop/rspec/expect_in_hook_spec.rb +0 -79
- data/spec/rubocop/cop/rspec/expect_output_spec.rb +0 -62
- data/spec/rubocop/cop/rspec/factory_bot/attribute_defined_statically_spec.rb +0 -208
- data/spec/rubocop/cop/rspec/factory_bot/create_list_spec.rb +0 -171
- data/spec/rubocop/cop/rspec/file_path_spec.rb +0 -200
- data/spec/rubocop/cop/rspec/focus_spec.rb +0 -139
- data/spec/rubocop/cop/rspec/hook_argument_spec.rb +0 -173
- data/spec/rubocop/cop/rspec/hooks_before_examples_spec.rb +0 -150
- data/spec/rubocop/cop/rspec/implicit_block_expectation_spec.rb +0 -135
- data/spec/rubocop/cop/rspec/implicit_expect_spec.rb +0 -102
- data/spec/rubocop/cop/rspec/implicit_subject_spec.rb +0 -188
- data/spec/rubocop/cop/rspec/instance_spy_spec.rb +0 -61
- data/spec/rubocop/cop/rspec/instance_variable_spec.rb +0 -95
- data/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +0 -39
- data/spec/rubocop/cop/rspec/it_behaves_like_spec.rb +0 -47
- data/spec/rubocop/cop/rspec/iterated_expectation_spec.rb +0 -82
- data/spec/rubocop/cop/rspec/leading_subject_spec.rb +0 -119
- data/spec/rubocop/cop/rspec/leaky_constant_declaration_spec.rb +0 -91
- data/spec/rubocop/cop/rspec/let_before_examples_spec.rb +0 -137
- data/spec/rubocop/cop/rspec/let_setup_spec.rb +0 -66
- data/spec/rubocop/cop/rspec/message_chain_spec.rb +0 -23
- data/spec/rubocop/cop/rspec/message_expectation_spec.rb +0 -45
- data/spec/rubocop/cop/rspec/message_spies_spec.rb +0 -151
- data/spec/rubocop/cop/rspec/missing_example_group_argument_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/multiple_describes_spec.rb +0 -30
- data/spec/rubocop/cop/rspec/multiple_expectations_spec.rb +0 -261
- data/spec/rubocop/cop/rspec/multiple_subjects_spec.rb +0 -83
- data/spec/rubocop/cop/rspec/named_subject_spec.rb +0 -123
- data/spec/rubocop/cop/rspec/nested_groups_spec.rb +0 -81
- data/spec/rubocop/cop/rspec/not_to_not_spec.rb +0 -77
- data/spec/rubocop/cop/rspec/overwriting_setup_spec.rb +0 -91
- data/spec/rubocop/cop/rspec/pending_spec.rb +0 -186
- data/spec/rubocop/cop/rspec/predicate_matcher_spec.rb +0 -354
- data/spec/rubocop/cop/rspec/rails/http_status_spec.rb +0 -90
- data/spec/rubocop/cop/rspec/receive_counts_spec.rb +0 -138
- data/spec/rubocop/cop/rspec/receive_never_spec.rb +0 -57
- data/spec/rubocop/cop/rspec/repeated_description_spec.rb +0 -76
- data/spec/rubocop/cop/rspec/repeated_example_spec.rb +0 -74
- data/spec/rubocop/cop/rspec/return_from_stub_spec.rb +0 -289
- data/spec/rubocop/cop/rspec/scattered_let_spec.rb +0 -28
- data/spec/rubocop/cop/rspec/scattered_setup_spec.rb +0 -98
- data/spec/rubocop/cop/rspec/shared_context_spec.rb +0 -137
- data/spec/rubocop/cop/rspec/shared_examples_spec.rb +0 -75
- data/spec/rubocop/cop/rspec/single_argument_message_chain_spec.rb +0 -178
- data/spec/rubocop/cop/rspec/subject_stub_spec.rb +0 -293
- data/spec/rubocop/cop/rspec/unspecified_exception_spec.rb +0 -177
- data/spec/rubocop/cop/rspec/verified_doubles_spec.rb +0 -86
- data/spec/rubocop/cop/rspec/void_expect_spec.rb +0 -49
- data/spec/rubocop/cop/rspec/yield_spec.rb +0 -81
- data/spec/rubocop/rspec/config_formatter_spec.rb +0 -52
- data/spec/rubocop/rspec/description_extractor_spec.rb +0 -63
- data/spec/rubocop/rspec/example_group_spec.rb +0 -44
- data/spec/rubocop/rspec/example_spec.rb +0 -62
- data/spec/rubocop/rspec/hook_spec.rb +0 -53
- data/spec/rubocop/rspec/language/selector_set_spec.rb +0 -53
- data/spec/rubocop/rspec/util/one_spec.rb +0 -23
- data/spec/rubocop/rspec/wording_spec.rb +0 -52
- data/spec/shared/autocorrect_behavior.rb +0 -9
- data/spec/shared/detects_style_behavior.rb +0 -9
- data/spec/shared/smoke_test_examples.rb +0 -27
- data/spec/smoke_tests/empty_spec.rb +0 -0
- data/spec/smoke_tests/factory_bot_spec.rb +0 -11
- data/spec/smoke_tests/no_tests_spec.rb +0 -4
- data/spec/smoke_tests/weird_rspec_spec.rb +0 -233
- data/spec/spec_helper.rb +0 -42
- data/spec/support/expect_offense.rb +0 -19
@@ -1,293 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::SubjectStub do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
it 'flags when subject is stubbed' do
|
7
|
-
expect_offense(<<-RUBY)
|
8
|
-
describe Foo do
|
9
|
-
subject(:foo) { described_class.new }
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(foo).to receive(:bar).and_return(baz)
|
13
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'uses expect twice' do
|
17
|
-
expect(foo.bar).to eq(baz)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
RUBY
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'flags when subject is mocked' do
|
24
|
-
expect_offense(<<-RUBY)
|
25
|
-
describe Foo do
|
26
|
-
subject(:foo) { described_class.new }
|
27
|
-
|
28
|
-
before do
|
29
|
-
expect(foo).to receive(:bar).and_return(baz)
|
30
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
31
|
-
expect(foo).to receive(:bar)
|
32
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
33
|
-
expect(foo).to receive(:bar).with(1)
|
34
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
35
|
-
expect(foo).to receive(:bar).with(1).and_return(2)
|
36
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses expect twice' do
|
40
|
-
expect(foo.bar).to eq(baz)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
RUBY
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'flags when an unnamed subject is mocked' do
|
47
|
-
expect_offense(<<-RUBY)
|
48
|
-
describe Foo do
|
49
|
-
subject { described_class.new }
|
50
|
-
|
51
|
-
it 'uses unnamed subject' do
|
52
|
-
expect(subject).to receive(:bar)
|
53
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
54
|
-
end
|
55
|
-
end
|
56
|
-
RUBY
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'flags an expectation made on an unnamed subject' do
|
60
|
-
expect_offense(<<-RUBY)
|
61
|
-
describe Foo do
|
62
|
-
subject(:foo) { described_class.new }
|
63
|
-
|
64
|
-
it 'uses unnamed subject' do
|
65
|
-
expect(subject).to receive(:bar)
|
66
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
67
|
-
end
|
68
|
-
end
|
69
|
-
RUBY
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'flags one-line expectcation syntax' do
|
73
|
-
expect_offense(<<-RUBY)
|
74
|
-
describe Foo do
|
75
|
-
subject(:foo) { described_class.new }
|
76
|
-
|
77
|
-
it 'uses one-line expectation syntax' do
|
78
|
-
is_expected.to receive(:bar)
|
79
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
80
|
-
end
|
81
|
-
end
|
82
|
-
RUBY
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'ignores stub within context where subject name changed' do
|
86
|
-
expect_no_offenses(<<-RUBY)
|
87
|
-
describe Foo do
|
88
|
-
subject(:foo) { described_class.new }
|
89
|
-
|
90
|
-
context 'when I shake things up' do
|
91
|
-
subject(:bar) { described_class.new }
|
92
|
-
|
93
|
-
it 'tries to trick rubocop-rspec' do
|
94
|
-
allow(foo).to receive(:baz)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
RUBY
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'flags stub inside all matcher' do
|
102
|
-
expect_offense(<<-RUBY)
|
103
|
-
describe Foo do
|
104
|
-
subject(:foo) { [Object.new] }
|
105
|
-
it 'tries to trick rubocop-rspec' do
|
106
|
-
expect(foo).to all(receive(:baz))
|
107
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
108
|
-
end
|
109
|
-
end
|
110
|
-
RUBY
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'flags nested subject stubs when nested subject uses same name' do
|
114
|
-
expect_offense(<<-RUBY)
|
115
|
-
describe Foo do
|
116
|
-
subject(:foo) { described_class.new }
|
117
|
-
|
118
|
-
context 'when I shake things up' do
|
119
|
-
subject(:foo) { described_class.new }
|
120
|
-
|
121
|
-
before do
|
122
|
-
allow(foo).to receive(:wow)
|
123
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'tries to trick rubocop-rspec' do
|
127
|
-
expect(foo).to eql(:neat)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'ignores nested stubs when nested subject is anonymous' do
|
135
|
-
expect_no_offenses(<<-RUBY)
|
136
|
-
describe Foo do
|
137
|
-
subject(:foo) { described_class.new }
|
138
|
-
|
139
|
-
context 'when I shake things up' do
|
140
|
-
subject { described_class.new }
|
141
|
-
|
142
|
-
before do
|
143
|
-
allow(foo).to receive(:wow)
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'tries to trick rubocop-rspec' do
|
147
|
-
expect(foo).to eql(:neat)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
RUBY
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'flags nested subject stubs when example group does not define subject' do
|
155
|
-
expect_offense(<<-RUBY)
|
156
|
-
describe Foo do
|
157
|
-
subject(:foo) { described_class.new }
|
158
|
-
|
159
|
-
context 'when I shake things up' do
|
160
|
-
before do
|
161
|
-
allow(foo).to receive(:wow)
|
162
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'tries to trick rubocop-rspec' do
|
166
|
-
expect(foo).to eql(:neat)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
RUBY
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'flags nested subject stubs' do
|
174
|
-
expect_offense(<<-RUBY)
|
175
|
-
describe Foo do
|
176
|
-
subject(:foo) { described_class.new }
|
177
|
-
|
178
|
-
context 'when I shake things up' do
|
179
|
-
subject(:bar) { described_class.new }
|
180
|
-
|
181
|
-
before do
|
182
|
-
allow(foo).to receive(:wow)
|
183
|
-
allow(bar).to receive(:wow)
|
184
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'tries to trick rubocop-rspec' do
|
188
|
-
expect(bar).to eql(foo)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
RUBY
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'flags nested subject stubs when adjacent context redefines' do
|
196
|
-
expect_offense(<<-RUBY)
|
197
|
-
describe Foo do
|
198
|
-
subject(:foo) { described_class.new }
|
199
|
-
|
200
|
-
context 'when I do something in a context' do
|
201
|
-
subject { blah }
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'still flags this test' do
|
205
|
-
allow(foo).to receive(:blah)
|
206
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
207
|
-
end
|
208
|
-
end
|
209
|
-
RUBY
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'flags deeply nested subject stubs' do
|
213
|
-
expect_offense(<<-RUBY)
|
214
|
-
describe Foo do
|
215
|
-
subject(:foo) { described_class.new }
|
216
|
-
|
217
|
-
context 'level 1' do
|
218
|
-
subject(:bar) { described_class.new }
|
219
|
-
|
220
|
-
context 'level 2' do
|
221
|
-
subject(:baz) { described_class.new }
|
222
|
-
|
223
|
-
before do
|
224
|
-
allow(foo).to receive(:wow)
|
225
|
-
allow(bar).to receive(:wow)
|
226
|
-
allow(baz).to receive(:wow)
|
227
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
RUBY
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'flags negated runners' do
|
236
|
-
expect_offense(<<-RUBY)
|
237
|
-
describe Foo do
|
238
|
-
subject(:foo) { described_class.new }
|
239
|
-
|
240
|
-
specify do
|
241
|
-
expect(foo).not_to receive(:bar)
|
242
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
243
|
-
expect(foo).to_not receive(:bar)
|
244
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
245
|
-
expect(foo.bar).to eq(baz)
|
246
|
-
end
|
247
|
-
end
|
248
|
-
RUBY
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'flags multiple-method stubs' do
|
252
|
-
expect_offense(<<-RUBY)
|
253
|
-
describe Foo do
|
254
|
-
subject(:foo) { described_class.new }
|
255
|
-
|
256
|
-
specify do
|
257
|
-
expect(foo).to receive_messages(bar: :baz, baz: :baz)
|
258
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
259
|
-
expect(foo.bar).to eq(baz)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
RUBY
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'flags chain stubs' do
|
266
|
-
expect_offense(<<-RUBY)
|
267
|
-
describe Foo do
|
268
|
-
subject(:foo) { described_class.new }
|
269
|
-
|
270
|
-
specify do
|
271
|
-
expect(foo).to receive_message_chain(:bar, baz: :baz)
|
272
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
273
|
-
expect(foo.bar.baz).to eq(baz)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
RUBY
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'flags spy subject stubs' do
|
280
|
-
expect_offense(<<-RUBY)
|
281
|
-
describe Foo do
|
282
|
-
subject(:foo) { described_class.new }
|
283
|
-
|
284
|
-
specify do
|
285
|
-
allow(foo).to some_matcher_that_allows_a_bar_message
|
286
|
-
expect(foo.bar).to eq(baz)
|
287
|
-
expect(foo).to have_received(:bar)
|
288
|
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not stub methods of the object under test.
|
289
|
-
end
|
290
|
-
end
|
291
|
-
RUBY
|
292
|
-
end
|
293
|
-
end
|
@@ -1,177 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe RuboCop::Cop::RSpec::UnspecifiedException do
|
4
|
-
subject(:cop) { described_class.new }
|
5
|
-
|
6
|
-
context 'with raise_error matcher' do
|
7
|
-
it 'detects the `unspecified_exception` offense' do
|
8
|
-
expect_offense(<<-RUBY)
|
9
|
-
expect {
|
10
|
-
raise StandardError
|
11
|
-
}.to raise_error
|
12
|
-
^^^^^^^^^^^ Specify the exception being captured
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'allows empty exception specification when not expecting an error' do
|
17
|
-
expect_no_offenses(<<-RUBY)
|
18
|
-
expect {
|
19
|
-
raise StandardError
|
20
|
-
}.not_to raise_error
|
21
|
-
RUBY
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'allows exception classes' do
|
25
|
-
expect_no_offenses(<<-RUBY)
|
26
|
-
expect {
|
27
|
-
raise StandardError
|
28
|
-
}.to raise_error(StandardError)
|
29
|
-
RUBY
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'allows exception messages' do
|
33
|
-
expect_no_offenses(<<-RUBY)
|
34
|
-
expect {
|
35
|
-
raise StandardError.new('error')
|
36
|
-
}.to raise_error('error')
|
37
|
-
RUBY
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'allows exception types with messages' do
|
41
|
-
expect_no_offenses(<<-RUBY)
|
42
|
-
expect {
|
43
|
-
raise StandardError.new('error')
|
44
|
-
}.to raise_error(StandardError, 'error')
|
45
|
-
RUBY
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'allows exception matching regular expressions' do
|
49
|
-
expect_no_offenses(<<-RUBY)
|
50
|
-
expect {
|
51
|
-
raise StandardError.new('error')
|
52
|
-
}.to raise_error(/err/)
|
53
|
-
RUBY
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'allows exception types with matching regular expressions' do
|
57
|
-
expect_no_offenses(<<-RUBY)
|
58
|
-
expect {
|
59
|
-
raise StandardError.new('error')
|
60
|
-
}.to raise_error(StandardError, /err/)
|
61
|
-
RUBY
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'allows classes with blocks with braces' do
|
65
|
-
expect_no_offenses(<<-RUBY)
|
66
|
-
expect {
|
67
|
-
raise StandardError.new('error')
|
68
|
-
}.to raise_error { |err| err.data }
|
69
|
-
RUBY
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'allows classes with blocks with do/end' do
|
73
|
-
expect_no_offenses(<<-RUBY)
|
74
|
-
expect {
|
75
|
-
raise StandardError.new('error')
|
76
|
-
}.to raise_error do |error|
|
77
|
-
error.data
|
78
|
-
end
|
79
|
-
RUBY
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'allows parameterized exceptions' do
|
83
|
-
expect_no_offenses(<<-RUBY)
|
84
|
-
my_exception = StandardError.new('my exception')
|
85
|
-
expect {
|
86
|
-
raise my_exception
|
87
|
-
}.to raise_error(my_exception)
|
88
|
-
RUBY
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'with raise_exception matcher' do
|
93
|
-
it 'detects the `unspecified_exception` offense' do
|
94
|
-
expect_offense(<<-RUBY)
|
95
|
-
expect {
|
96
|
-
raise StandardError
|
97
|
-
}.to raise_exception
|
98
|
-
^^^^^^^^^^^^^^^ Specify the exception being captured
|
99
|
-
RUBY
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'allows empty exception specification when not expecting an error' do
|
103
|
-
expect_no_offenses(<<-RUBY)
|
104
|
-
expect {
|
105
|
-
raise StandardError
|
106
|
-
}.not_to raise_exception
|
107
|
-
RUBY
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'allows exception classes' do
|
111
|
-
expect_no_offenses(<<-RUBY)
|
112
|
-
expect {
|
113
|
-
raise StandardError
|
114
|
-
}.to raise_exception(StandardError)
|
115
|
-
RUBY
|
116
|
-
end
|
117
|
-
|
118
|
-
it 'allows exception messages' do
|
119
|
-
expect_no_offenses(<<-RUBY)
|
120
|
-
expect {
|
121
|
-
raise StandardError.new('error')
|
122
|
-
}.to raise_exception('error')
|
123
|
-
RUBY
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'allows exception types with messages' do
|
127
|
-
expect_no_offenses(<<-RUBY)
|
128
|
-
expect {
|
129
|
-
raise StandardError.new('error')
|
130
|
-
}.to raise_exception(StandardError, 'error')
|
131
|
-
RUBY
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'allows exception matching regular expressions' do
|
135
|
-
expect_no_offenses(<<-RUBY)
|
136
|
-
expect {
|
137
|
-
raise StandardError.new('error')
|
138
|
-
}.to raise_exception(/err/)
|
139
|
-
RUBY
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'allows exception types with matching regular expressions' do
|
143
|
-
expect_no_offenses(<<-RUBY)
|
144
|
-
expect {
|
145
|
-
raise StandardError.new('error')
|
146
|
-
}.to raise_exception(StandardError, /err/)
|
147
|
-
RUBY
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'allows classes with blocks with braces' do
|
151
|
-
expect_no_offenses(<<-RUBY)
|
152
|
-
expect {
|
153
|
-
raise StandardError.new('error')
|
154
|
-
}.to raise_exception { |err| err.data }
|
155
|
-
RUBY
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'allows classes with blocks with do/end' do
|
159
|
-
expect_no_offenses(<<-RUBY)
|
160
|
-
expect {
|
161
|
-
raise StandardError.new('error')
|
162
|
-
}.to raise_exception do |error|
|
163
|
-
error.data
|
164
|
-
end
|
165
|
-
RUBY
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'allows parameterized exceptions' do
|
169
|
-
expect_no_offenses(<<-RUBY)
|
170
|
-
my_exception = StandardError.new('my exception')
|
171
|
-
expect {
|
172
|
-
raise my_exception
|
173
|
-
}.to raise_exception(my_exception)
|
174
|
-
RUBY
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|