rubocop-rspec icon indicating copy to clipboard operation
rubocop-rspec copied to clipboard

Fix: Fix false negative for `RSpec/Dialect` when specified Capybara-specific methods

Open sanfrecce-osaka opened this issue 5 months ago • 3 comments

fixed https://github.com/rubocop/rubocop-rspec/issues/1951

RuboCop::Cop::RSpec::Dialect#rspec_method? detects if node's second child is an RSpec block using RuboCop::RSpec::Language::ALL.all. However, RuboCop::Cop::RSpec::Dialect#rspec_method? returned nil because the following Capybara-specific methods were not set in config/default.yml.

  • given
  • given!
  • background

I remove the line that checks if it’s a rspec_method? and add a inside_example_group? check.

cf. https://github.com/rubocop/rubocop-rspec/issues/1951#issuecomment-2296916136

Due to the above, it wouldn't filter out are calls with an explicit receiver where the receiver is not RSpec, eg foo.describe. so the following examples were removed.

  • allows calling methods named xxx in examples

Before submitting the PR make sure the following are checked:

  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [ ] Updated documentation.
  • [x] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • [x] The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • [ ] Added the new cop to config/default.yml.
  • [ ] The cop is configured as Enabled: pending in config/default.yml.
  • [ ] The cop is configured as Enabled: true in .rubocop.yml.
  • [ ] The cop documents examples of good and bad code.
  • [ ] The tests assert both that bad code is reported and that good code is not reported.
  • [ ] Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • [ ] Set VersionChanged: "<<next>>" in config/default.yml.

sanfrecce-osaka avatar Aug 26 '24 12:08 sanfrecce-osaka