File tree Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Expand file tree Collapse file tree 3 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 3
3
## Master (Unreleased)
4
4
5
5
- Add support ` be_status ` style for ` RSpec/Rails/HttpStatus ` . ([ @ydah ] )
6
+ - Fix a false positive for ` RSpec/DescribedClassModuleWrapping ` when RSpec.describe numblock is nested within a module. ([ @ydah ] )
6
7
- Add new ` RSpec/IndexedLet ` cop. ([ @dmitrytsepelev ] )
7
8
- Fix order of expected and actual in correction for ` RSpec/Rails/MinitestAssertions ` ([ @mvz ] )
8
9
- Fix a false positive for ` RSpec/FactoryBot/ConsistentParenthesesStyle ` inside ` && ` , ` || ` and ` :? ` when ` omit_parentheses ` is on ([ @dmitrytsepelev ] )
Original file line number Diff line number Diff line change @@ -22,15 +22,15 @@ module RSpec
22
22
class DescribedClassModuleWrapping < Base
23
23
MSG = 'Avoid opening modules and defining specs within them.'
24
24
25
- # @!method find_rspec_blocks (node)
26
- def_node_search :find_rspec_blocks , <<~PATTERN
27
- (block (send #explicit_rspec? #ExampleGroups.all ...) ...)
25
+ # @!method include_rspec_blocks? (node)
26
+ def_node_search :include_rspec_blocks? , <<~PATTERN
27
+ ({ block numblock} (send #explicit_rspec? #ExampleGroups.all ...) ...)
28
28
PATTERN
29
29
30
30
def on_module ( node )
31
- find_rspec_blocks ( node ) do
32
- add_offense ( node )
33
- end
31
+ return unless include_rspec_blocks? ( node )
32
+
33
+ add_offense ( node )
34
34
end
35
35
end
36
36
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- RSpec . describe RuboCop ::Cop ::RSpec ::DescribedClassModuleWrapping do
3
+ RSpec . describe RuboCop ::Cop ::RSpec ::DescribedClassModuleWrapping , :ruby27 do
4
4
it 'allows a describe block in the outermost scope' do
5
5
expect_no_offenses ( <<-RUBY )
6
6
RSpec.describe MyClass do
9
9
RUBY
10
10
end
11
11
12
- it 'registers an offense when RSpec.describe is nested within a module' do
12
+ it 'registers an offense when RSpec.describe block is nested ' \
13
+ 'within a module' do
13
14
expect_offense ( <<-RUBY )
14
15
module MyModule
15
16
^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
@@ -21,7 +22,21 @@ module MyModule
21
22
RUBY
22
23
end
23
24
24
- it 'registers an offense when RSpec.describe is nested within two modules' do
25
+ it 'registers an offense when RSpec.describe numblock is nested ' \
26
+ 'within a module' do
27
+ expect_offense ( <<-RUBY )
28
+ module MyModule
29
+ ^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
30
+ RSpec.describe MyClass do
31
+ _1
32
+ subject { "MyClass" }
33
+ end
34
+ end
35
+ RUBY
36
+ end
37
+
38
+ it 'registers an offense when RSpec.describe block is nested ' \
39
+ 'within two modules' do
25
40
expect_offense ( <<-RUBY )
26
41
module MyFirstModule
27
42
^^^^^^^^^^^^^^^^^^^^ Avoid opening modules and defining specs within them.
@@ -36,7 +51,7 @@ module MySecondModule
36
51
RUBY
37
52
end
38
53
39
- it 'allows a module that does not contain RSpec.describe' do
54
+ it 'allows a module that does not contain RSpec.describe block ' do
40
55
expect_no_offenses ( <<-RUBY )
41
56
module MyModule
42
57
def some_method
You can’t perform that action at this time.
0 commit comments