-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a cop to check for consistent method usage in feature specs. #439
Conversation
998bc6d
to
1208b18
Compare
1208b18
to
a443b44
Compare
I started down the path of making this If someone were to set
I wasn't sure of the best way to handle those two conditions, so I'm open to feedback on making this configurable. |
class FeatureMethods < Cop | ||
MSG = 'Use `%s` instead of `%s`.'.freeze | ||
|
||
# https://git.io/v7rLu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you hit y
on your keyboard when visiting this link then github will give you a link to a sha that will never break. https://help.github.com/articles/getting-permanent-links-to-files/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated.
a443b44
to
92d251c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I’ve been trying to find out why capybara provides these aliased methods. The README just says that “Capybara also comes with a built in DSL for creating descriptive acceptance tests […] Also, I just want to note that these aliases are only available if Capybara (or rspec-rails) is loaded. Which puts this cop in the same category as |
@bquorning I believe they're just syntactic sugar to make feature specs read more like Cucumber features. |
Yup, this should be in RSpec::Capybara module. There are few other things we could implement for capybara (like #378 for example) |
92d251c
to
80e3a73
Compare
Moved the cop to a new |
'factory_girl' => 'FactoryGirl' | ||
} | ||
glob = SpecHelper::ROOT.join('lib', 'rubocop', 'cop', | ||
'rspec', '{,factory_girl/}*.rb') | ||
'rspec', '{capybara/,,factory_girl/}*.rb') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requiring these two changes might get messy quickly if you anticipate adding more namespaces, but I went with the simplest thing for now.
Can't see what the build failures are since they're private. |
@rspeicher you can run
|
Ahh, I think you need to add |
Back to green, thanks y'all! |
config/default.yml
Outdated
Capybara/FeatureMethods: | ||
Description: Checks for consistent method usage in feature specs. | ||
Enabled: true | ||
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/Capybara/FeatureMethods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this link and the one below it are wrong -- the namespace should be RuboCop/Cop/RSpec/{Capybara,FactoryGirl}
, no?
@@ -8,7 +8,7 @@ require 'rubocop-rspec' | |||
require 'rubocop/rspec/description_extractor' | |||
require 'rubocop/rspec/config_formatter' | |||
|
|||
cops = '{*.rb,factory_girl/*.rb}' | |||
cops = '{*.rb,capybara/*.rb,factory_girl/*.rb}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to just **/*.rb
.
aa8a130
to
00337e3
Compare
Rebased since 1.16.0 was released. |
All cops need to be nested under `RuboCop/Cop/RSpec`, but cops nested under `Capybara` and `FactoryGirl` were missing the `RSpec` part.
00337e3
to
a39ce8b
Compare
@@ -22,7 +22,7 @@ def unified_config | |||
cops.each_with_object(config.dup) do |cop, unified| | |||
unified[cop] = config.fetch(cop) | |||
.merge(descriptions.fetch(cop)) | |||
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop) | |||
.merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', '')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer an anchored regex here?
I think it's ready for merge. @backus final words? |
LGTM. @rspeicher or @Darhazer (whoever does the merge) can you squash down the commits? |
No description provided.