Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sanfrecce-osaka
Copy link

fixed #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. #1951 (comment)

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:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • 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.

…pecific methods

fixed rubocop#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. rubocop#1951 (comment)

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
@sanfrecce-osaka sanfrecce-osaka requested a review from a team as a code owner August 26, 2024 12:18
@sanfrecce-osaka
Copy link
Author

Should I also change the following document as it no longer checks for RuboCop::RSpec::Language::ALL.all?

# A dialect can be based on the following RSpec methods:
#
# - describe, context, feature, example_group
# - xdescribe, xcontext, xfeature
# - fdescribe, fcontext, ffeature
# - shared_examples, shared_examples_for, shared_context
# - it, specify, example, scenario, its
# - fit, fspecify, fexample, fscenario, focus
# - xit, xspecify, xexample, xscenario, skip
# - pending
# - prepend_before, before, append_before,
# - around
# - prepend_after, after, append_after
# - let, let!
# - subject, subject!
# - expect, is_expected, expect_any_instance_of

@pirj
Copy link
Member

pirj commented Aug 26, 2024

change the following document

Maybe. I find it hard to understand what the “based” means in “dialect can be based on the following RSpec methods”, though.

Can you think of a simpler description?

RSpec.context 'context' do
^^^^^^^^^^^^^^^^^^^^^^^ Prefer `describe` over `context`.
it 'tests common context invocations' do
expect(request.context).to be_empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those ones were here to ensure that context with an explicit receiver is not detected. Can you keep it in some way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RSpec/Dialect causes a false negative when using below setting mentioned in the documentation
2 participants