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

Fixed typo for AssertIncludes cop. Changed includes -> include #19

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#19](https://github.com/rubocop-hq/rubocop-minitest/pull/19): Fix a false negative for `Minitest/AssertIncludes` when using `include` method in arguments of `assert` method. ([@abhaynikam][])

## 0.2.1 (2019-09-24)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Minitest/AssertEmpty:
VersionAdded: '0.2'

Minitest/AssertIncludes:
Description: 'Check if your test uses `assert_includes` instead of `assert(collection.includes?(actual))`.'
Description: 'Check if your test uses `assert_includes` instead of `assert(collection.include?(actual))`.'
StyleGuide: 'https://github.com/rubocop-hq/minitest-style-guide#assert-includes'
Enabled: true
VersionAdded: '0.2'
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/minitest/assert_includes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module RuboCop
module Cop
module Minitest
# Check if your test uses `assert_includes`
# instead of `assert(collection.includes?(actual))`.
# instead of `assert(collection.include?(actual))`.
#
# @example
# # bad
# assert(collection.includes?(actual))
# assert(collection.includes?(actual), 'the message')
# assert(collection.include?(actual))
# assert(collection.include?(actual), 'the message')
#
# # good
# assert_includes(collection, actual)
Expand All @@ -20,7 +20,7 @@ class AssertIncludes < Cop
'`assert(%<receiver>s)`.'

def_node_matcher :assert_with_includes, <<~PATTERN
(send nil? :assert $(send $_ :includes? $_) $...)
(send nil? :assert $(send $_ :include? $_) $...)
PATTERN

def on_send(node)
Expand Down
6 changes: 3 additions & 3 deletions manual/cops_minitest.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChan
Enabled | Yes | Yes | 0.2 | -

Check if your test uses `assert_includes`
instead of `assert(collection.includes?(actual))`.
instead of `assert(collection.include?(actual))`.

### Examples

```ruby
# bad
assert(collection.includes?(actual))
assert(collection.includes?(actual), 'the message')
assert(collection.include?(actual))
assert(collection.include?(actual), 'the message')

# good
assert_includes(collection, actual)
Expand Down
24 changes: 12 additions & 12 deletions test/rubocop/cop/minitest/assert_includes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def setup
@cop = RuboCop::Cop::Minitest::AssertIncludes.new
end

def test_registers_offense_when_using_assert_with_includes
def test_registers_offense_when_using_assert_with_include
assert_offense(<<~RUBY, @cop)
class FooTest < Minitest::Test
def test_do_something
assert(collection.includes?(actual))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual)` over `assert(collection.includes?(actual))`.
assert(collection.include?(actual))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual)` over `assert(collection.include?(actual))`.
end
end
RUBY
Expand All @@ -26,12 +26,12 @@ def test_do_something
RUBY
end

def test_registers_offense_when_using_assert_with_includes_and_message
def test_registers_offense_when_using_assert_with_include_and_message
assert_offense(<<~RUBY, @cop)
class FooTest < Minitest::Test
def test_do_something
assert(collection.includes?(actual), 'the message')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, 'the message')` over `assert(collection.includes?(actual), 'the message')`.
assert(collection.include?(actual), 'the message')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, 'the message')` over `assert(collection.include?(actual), 'the message')`.
end
end
RUBY
Expand All @@ -45,13 +45,13 @@ def test_do_something
RUBY
end

def test_registers_offense_when_using_assert_with_includes_and_variable_message
def test_registers_offense_when_using_assert_with_include_and_variable_message
assert_offense(<<~RUBY, @cop)
class FooTest < Minitest::Test
def test_do_something
message = 'the message'
assert(collection.includes?(actual), message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, message)` over `assert(collection.includes?(actual), message)`.
assert(collection.include?(actual), message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, message)` over `assert(collection.include?(actual), message)`.
end
end
RUBY
Expand All @@ -66,14 +66,14 @@ def test_do_something
RUBY
end

def test_registers_offense_when_using_assert_with_includes_and_constant_message
def test_registers_offense_when_using_assert_with_include_and_constant_message
assert_offense(<<~RUBY, @cop)
class FooTest < Minitest::Test
MESSAGE = 'the message'

def test_do_something
assert(collection.includes?(actual), MESSAGE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, MESSAGE)` over `assert(collection.includes?(actual), MESSAGE)`.
assert(collection.include?(actual), MESSAGE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer using `assert_includes(collection, actual, MESSAGE)` over `assert(collection.include?(actual), MESSAGE)`.
end
end
RUBY
Expand Down