File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Master (Unreleased)
4
4
5
+ - Fix false-positive for ` RSpec/UnspecifiedException ` when a method is literally named ` raise_exception ` . ([ @aarestad ] )
6
+
5
7
## 3.0.5 (2024-09-07)
6
8
7
9
- Fix false-negative and error for ` RSpec/MetadataStyle ` when non-literal args are used in metadata in ` EnforceStyle: hash ` . ([ @cbliard ] )
@@ -899,6 +901,7 @@ Compatibility release so users can upgrade RuboCop to 0.51.0. No new features.
899
901
900
902
<!-- Contributors (alphabetically) -->
901
903
904
+ [ @aarestad ] : https://github.com/aarestad
902
905
[ @abrom ] : https://github.com/abrom
903
906
[ @ahukkanen ] : https://github.com/ahukkanen
904
907
[ @akiomik ] : https://github.com/akiomik
Original file line number Diff line number Diff line change @@ -62,7 +62,10 @@ def empty_exception_matcher?(node)
62
62
end
63
63
64
64
def find_expect_to ( node )
65
- node . each_ancestor ( :send ) . find do |ancestor |
65
+ node . each_ancestor . find do |ancestor |
66
+ break if ancestor . block_type?
67
+ next unless ancestor . send_type?
68
+
66
69
expect_to? ( ancestor )
67
70
end
68
71
end
Original file line number Diff line number Diff line change 85
85
}.to raise_error(my_exception)
86
86
RUBY
87
87
end
88
+
89
+ it 'allows a subject function to be named raise_error' do
90
+ expect_no_offenses ( <<~RUBY )
91
+ def raise_exception
92
+ raise StandardError
93
+ end
94
+
95
+ expect {
96
+ raise_error
97
+ }.to raise_error(StandardError)
98
+ RUBY
99
+ end
100
+
101
+ it 'allows a subject function to be named raise_exception' do
102
+ expect_no_offenses ( <<~RUBY )
103
+ def raise_exception
104
+ raise StandardError
105
+ end
106
+
107
+ expect {
108
+ raise_exception
109
+ }.to raise_error(StandardError)
110
+ RUBY
111
+ end
88
112
end
89
113
90
114
context 'with raise_exception matcher' do
198
222
^^^^^^^^^^^^^^^ Specify the exception being captured
199
223
RUBY
200
224
end
225
+
226
+ it 'allows a subject function to be named raise_exception' do
227
+ expect_no_offenses ( <<~RUBY )
228
+ def raise_error
229
+ raise StandardError
230
+ end
231
+
232
+ expect {
233
+ raise_exception
234
+ }.to raise_exception(StandardError)
235
+ RUBY
236
+ end
237
+
238
+ it 'allows a subject function to be named raise_error' do
239
+ expect_no_offenses ( <<~RUBY )
240
+ def raise_error
241
+ raise StandardError
242
+ end
243
+
244
+ expect {
245
+ raise_error
246
+ }.to raise_exception(StandardError)
247
+ RUBY
248
+ end
201
249
end
202
250
end
You can’t perform that action at this time.
0 commit comments