File tree 3 files changed +24
-3
lines changed
lib/rubocop/cop/rspec/capybara
spec/rubocop/cop/rspec/capybara
3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 3
3
## Master (Unreleased)
4
4
5
5
* Fix false positive in ` RSpec/EmptyExampleGroup ` cop when methods named like a RSpec method are used. ([ @Darhazer ] [ ] )
6
+ * Fix ` Capybara/FeatureMethods ` not working when there is require before the spec. ([ @Darhazer ] [ ] )
6
7
7
8
## 1.25.1 (2018-04-10)
8
9
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class FeatureMethods < Cop
66
66
PATTERN
67
67
68
68
def on_block ( node )
69
- return unless spec? ( root_node )
69
+ return unless inside_spec? ( node )
70
70
71
71
feature_method ( node ) do |send_node , match |
72
72
next if enabled? ( match )
@@ -87,8 +87,19 @@ def autocorrect(node)
87
87
88
88
private
89
89
90
- def root_node
91
- processed_source . ast
90
+ def inside_spec? ( node )
91
+ return spec? ( node ) if root_node? ( node )
92
+
93
+ root = node . ancestors . find { |parent | root_node? ( parent ) }
94
+ spec? ( root )
95
+ end
96
+
97
+ def root_node? ( node )
98
+ node . parent . nil? || root_with_siblings? ( node . parent )
99
+ end
100
+
101
+ def root_with_siblings? ( node )
102
+ node . begin_type? && node . parent . nil?
92
103
end
93
104
94
105
def enabled? ( method_name )
Original file line number Diff line number Diff line change 76
76
RUBY
77
77
end
78
78
79
+ it 'allows includes before the spec' do
80
+ expect_offense ( <<-RUBY )
81
+ require 'rails_helper'
82
+
83
+ RSpec.feature 'Foo' do; end
84
+ ^^^^^^^ Use `describe` instead of `feature`.
85
+ RUBY
86
+ end
87
+
79
88
context 'with configured `EnabledMethods`' do
80
89
let ( :cop_config ) { { 'EnabledMethods' => %w[ feature ] } }
81
90
You can’t perform that action at this time.
0 commit comments