File tree 4 files changed +29
-3
lines changed
4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 5
5
- Fix false positive in ` RSpec/Pending ` , where it would mark the default block ` it ` as an offense. ([ @bquorning ] )
6
6
- Fix issue when ` Style/ContextWording ` is configured with a Prefix being interpreted as a boolean, like ` on ` . ([ @sakuro ] )
7
7
- Add new ` RSpec/IncludeExamples ` cop to enforce using ` it_behaves_like ` over ` include_examples ` . ([ @dvandersluis ] )
8
+ - Change ` RSpec/ScatteredSetup ` to allow ` around ` hooks to be scattered. ([ @ydah ] )
8
9
9
10
## 3.5.0 (2025-02-16)
10
11
Original file line number Diff line number Diff line change @@ -5524,7 +5524,9 @@ end
5524
5524
5525
5525
Checks for setup scattered across multiple hooks in an example group.
5526
5526
5527
- Unify `before`, `after`, and `around` hooks when possible.
5527
+ Unify `before` and `after` hooks when possible.
5528
+ However, `around` hooks are allowed to be defined multiple times,
5529
+ as unifying them would typically make the code harder to read.
5528
5530
5529
5531
[#examples-rspecscatteredsetup]
5530
5532
=== Examples
@@ -5544,6 +5546,12 @@ describe Foo do
5544
5546
setup2
5545
5547
end
5546
5548
end
5549
+
5550
+ # good
5551
+ describe Foo do
5552
+ around { |example| before1; example.call; after1 }
5553
+ around { |example| before2; example.call; after2 }
5554
+ end
5547
5555
----
5548
5556
5549
5557
[#references-rspecscatteredsetup]
Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ module Cop
5
5
module RSpec
6
6
# Checks for setup scattered across multiple hooks in an example group.
7
7
#
8
- # Unify `before`, `after`, and `around` hooks when possible.
8
+ # Unify `before` and `after` hooks when possible.
9
+ # However, `around` hooks are allowed to be defined multiple times,
10
+ # as unifying them would typically make the code harder to read.
9
11
#
10
12
# @example
11
13
# # bad
@@ -22,6 +24,12 @@ module RSpec
22
24
# end
23
25
# end
24
26
#
27
+ # # good
28
+ # describe Foo do
29
+ # around { |example| before1; example.call; after1 }
30
+ # around { |example| before2; example.call; after2 }
31
+ # end
32
+ #
25
33
class ScatteredSetup < Base
26
34
include FinalEndLocation
27
35
include RangeHelp
@@ -48,7 +56,7 @@ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
48
56
def repeated_hooks ( node )
49
57
hooks = RuboCop ::RSpec ::ExampleGroup . new ( node )
50
58
. hooks
51
- . select ( & : knowable_scope?)
59
+ . select { | hook | hook . knowable_scope? && hook . name != :around }
52
60
. group_by { |hook | [ hook . name , hook . scope , hook . metadata ] }
53
61
. values
54
62
. reject ( &:one? )
Original file line number Diff line number Diff line change 58
58
RUBY
59
59
end
60
60
61
+ it 'ignores around hooks' do
62
+ expect_no_offenses ( <<~RUBY )
63
+ describe Foo do
64
+ around { bar }
65
+ around { baz }
66
+ end
67
+ RUBY
68
+ end
69
+
61
70
it 'ignores different hooks' do
62
71
expect_no_offenses ( <<~RUBY )
63
72
describe Foo do
You can’t perform that action at this time.
0 commit comments