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

Add cop to enforce refute_includes over refute(collection.include?(actual)) #15

Merged

Conversation

abhaynikam
Copy link
Contributor

PR adds cops to enforce the use of refute_includes over refute(collection.includes?(actual))

Ref: https://github.com/rubocop-hq/minitest-style-guide#refute-includes

@abhaynikam abhaynikam force-pushed the add-style-guide-for-refute-includes branch 2 times, most recently from 1fb6b7b to 25f116b Compare September 27, 2019 17:15
@abhaynikam
Copy link
Contributor Author

Not sure why CI fails. It passes on my local. I did run the documentation command before pushing. can anyone please help me with it?

@koic
Copy link
Member

koic commented Sep 28, 2019

This repository allow ruby-head to fail. There is no problem if other matrices are successful.

assert_offense(<<~RUBY, @cop)
class FooTest < Minitest::Test
def test_do_something
refute(collection.includes?(actual))
Copy link
Member

Choose a reason for hiding this comment

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

Please check against include method instead of includes method.
rubocop/minitest-style-guide#17

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koic : Resolved the typo and squashed my commits. Please have a look.

@abhaynikam abhaynikam force-pushed the add-style-guide-for-refute-includes branch 2 times, most recently from d4f63e3 to 16ba08e Compare October 1, 2019 05:33
@abhaynikam abhaynikam changed the title Add cop to enforce refute_includes over refute(collection.includes?(actual)) Add cop to enforce refute_includes over refute(collection.include?(actual)) Oct 1, 2019
@koic
Copy link
Member

koic commented Oct 3, 2019

This PR has conflicts. Can you rebase with the latest master branch?

@abhaynikam abhaynikam force-pushed the add-style-guide-for-refute-includes branch from 16ba08e to a5f5f25 Compare October 3, 2019 05:37
@abhaynikam
Copy link
Contributor Author

@koic : Resolved merge conflict. Please have a look.

module RuboCop
module Cop
module Minitest
# Check if your test uses `refute_includes`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is worded confusingly as now it implies that refutes_includes is what's bad.

RUBY
end

def test_registers_offense_when_using_refute_with_include_and_variable_message
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as with the other PR - I don't see a point in having separate tests for a variable message and a constant message. Relying on the param count should be enough here.

@abhaynikam abhaynikam force-pushed the add-style-guide-for-refute-includes branch from a5f5f25 to 0d0db24 Compare October 7, 2019 05:51
@abhaynikam
Copy link
Contributor Author

@bbatsov : Resolved both the comments. Can you please have a look?

RUBY
end

def test_registers_offense_when_using_refute_with_include_and_constant_message
Copy link
Contributor

Choose a reason for hiding this comment

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

There's still this pointless test with a constant message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. My bad. Removing it now.

#
# @example
# # bad
# refute(collection.include?(actual))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use object instead of actual everywhere in the test.

@abhaynikam abhaynikam force-pushed the add-style-guide-for-refute-includes branch from 0d0db24 to 9ab99d6 Compare October 7, 2019 06:32
@abhaynikam
Copy link
Contributor Author

@bbatsov : Resolve the comments.

@bbatsov bbatsov merged commit da21109 into rubocop:master Oct 7, 2019
@bbatsov
Copy link
Contributor

bbatsov commented Oct 7, 2019

Looks good. Thanks!

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.

None yet

3 participants