-
-
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
RSpec/Dialect causes a false negative when using below setting mentioned in the documentation #1951
Comments
Thanks for reporting! The Would you like to send a PR to fix this? |
Thank you for your response.
Yes, I would. I was reading the code, and found that it is due to the lack of |
This cop should handle any source DEL without needing to configure it in the Language section. You just tell the cop to change background to describe, and that’s it. So for the PR, I suggest just removing the line that checks if it’s a |
Thanks for the suggestion. The check with RSpec.describe 'context' do
it 'tests common context invocations' do
expect(request.context).to be_empty? # 👮♂️ C: [Correctable] RSpec/Dialect: Prefer describe over context.
end
end So how about changing it to the following? class Dialect < Base
extend AutoCorrector
include MethodPreference
+ include InsideExampleGroup
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
# @!method rspec_method?(node)
- def_node_matcher :rspec_method?, '(send #rspec? #ALL.all ...)'
+ def_node_matcher :rspec_method?, '(send #rspec? ...)'
def on_send(node)
+ return unless inside_example_group?(node)
return unless rspec_method?(node)
return unless preferred_methods[node.method_name]
msg = format(MSG, prefer: preferred_method(node.method_name),
current: node.method_name)
add_offense(node, message: msg) do |corrector|
current = node.loc.selector
preferred = preferred_method(current.source)
corrector.replace(current, preferred)
end
end
end Also, describe 'display name presence' do # `inside_example_group?` returns true
end
before do # `inside_example_group?` returns false
end
RSpec.describe 'context' do
before do # `inside_example_group?` returns true
end
describe 'display name presence' do # `inside_example_group?` returns true
end
end Does this behaviour need fixing? |
|
I think the inside_example_group? is fine because it returns true for the top-level example group like yours, and this will trigger for the top-level |
…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
Thank you for your feedback. |
RSpec/Dialect causes a false negative when using below setting mentioned in the documentation.
cf. https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecdialect
Expected behavior
The following code should not be passed:
Actual behavior
The following code is passed:
In contrast, the following codes doesn't pass.
I look like
rspec_method?
returns nil whennode.method_name
isbackground
.rubocop-rspec/lib/rubocop/cop/rspec/dialect.rb
Lines 67 to 80 in e02576f
RuboCop version
The text was updated successfully, but these errors were encountered: