-
-
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/NoExpectationExample
false positives
#1385
Comments
This comment was marked as resolved.
This comment was marked as resolved.
It also does not accept it "is not authorized" do
assert_text("You are not authorized to perform this action.")
end |
This comment was marked as outdated.
This comment was marked as outdated.
@annaswims you can add |
Thanks! I missed the docs |
I think we have to account for the expectations in hooks that are in scope. We have the Maybe we also should add the capybara expectations by default to the language (perhaps behind a config option). I'm on a fense for this one, as it would affect things like @rubocop/rubocop-rspec WDYT? |
I think this would be much easier to check with dynamic analysis that with static analysis. @pirj Is this something that might be built into RSpec itself one day? |
No, it's not possible (to do this reliably) in RSpec, too, since rspec-mocks/rspec-expectations are not the only way of making expectations, e.g. |
I have reviewed a codebase with the cop applied, and now I think that we may add an |
My case with I've got shared_examples(
'for all enum predicate methods'
) do |predicate_method_names, *expectations|
predicate_method_names.each do |predicate_method_name|
describe predicate_method_name do
subject { item_class.new.public_send(predicate_method_name) }
## rubocop:disable RSpec/NoExpectationExample
specify do
Array(expectations).each do |expectation|
instance_exec(&expectation)
end
end
## rubocop:enable RSpec/NoExpectationExample
end
end
end I understand, meta-programming is difficult for linters like RuboCop. But I've also got:
That's non-sense!
|
This would be better reported to the parent project https://github.com/rubocop/rubocop/issues/
Not only. Also for people if its sole purpose is to make things dry rather than more readable. Looking at the spec: status_enum_values = %w[created selected canceled]
describe 'predicate_methods option' do
convert_enum_values_to_predicate_methods = lambda do |enum_values|
enum_values.map { |enum_value| :"#{enum_value}?" }
end
status_enum_predicate_methods =
convert_enum_values_to_predicate_methods.call status_enum_values
include_examples 'for all enum predicate methods',
status_enum_predicate_methods,
-> { expect(subject).to be false } leads me to a thought that this can be written as status_enum_values = %w[created selected canceled]
describe 'predicate_methods option' do
status_enum_values.each do |status_enum_value|
subject { item_class.new.public_send("#{status_enum_value}?") }
it 'returns false' do
expect(subject).to be(false)
end
end
end Or: status_enum_values = %w[created selected canceled]
shared_examples 'returns false' do |status_enum_value|
subject { item_class.new.public_send("#{status_enum_value}?") }
it 'returns false' do
expect(subject).to be(false)
end
end
status_enum_values.each do |status_enum_value|
it_behaves_like 'returns false', status_enum_value
end Am I missing something? Do those options look worse from your perspective, @AlexWayfer ? |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Personally, I follow the recommendation to use helper methods that is supported by the Effective Testing with RSpec book. However, since for static checking it creates complications, do you think we can all agree that if something is an expectation, we can name it as such? def expect_low_value
expect(product.value).to be_between(0, 50)
end
context 'during summer' do
it 'has low value' do
expect_low_value
end
end In such a way, we can introduce an option with a default to the cop, say, Eventually, this can become part of the community RSpec style guide if it gets some traction. How does that sound? PS My apologies for an attempt to steal the idea, this is what @Darhazer suggests above. |
This comment was marked as resolved.
This comment was marked as resolved.
RSpec/ExpectInHook disapproves such style, @ShockwaveNN |
Does anyone want to send a PR to introduce |
If no one plans to send a PR, I will send. How do you like it? |
There's no better candidate than you, @ydah with so many recent contributions, please go for it. |
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop/rubocop-rspec#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop/rubocop-rspec#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop/rubocop-rspec#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
…mple` Fix: rubocop/rubocop-rspec#1385 This cop can be customized allowed expectation methods pattern with `AllowedPatterns`. \Aexpect_ and \Aassert_ are allowed by default. ### @ example `AllowedPatterns: [\Aexpect_]` ```ruby # bad it do not_expect_something end # good it do expect_something end ```
This gives
RSpec/NoExpectationExample
but it shouldn't. :)The text was updated successfully, but these errors were encountered: