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 "Assert Nil" rule #2

Merged
merged 1 commit into from Aug 8, 2019

Conversation

@koic
Copy link
Member

commented Aug 8, 2019

Use assert_nil if expecting nil.

# bad
assert_equal(nil, actual)

# good
assert_nil(actual)

This rule prevents the following MT6's deprecated warning:

class ExampleTest < Minitest::Test
  def test_expecting_nil
    foo = nil

    assert_equal(nil, foo)
  end
end
% bundle exec rake test
Run options: --seed 16727

# Running:

DEPRECATED: Use assert_nil if expecting nil from
/Users/koic/src/github.com/rubocop-hq/rubocop-minitest/test/rubocop/minitest_test.rb:13. This
will fail in Minitest 6.

https://github.com/seattlerb/minitest/blob/ab39d35fb4e84eb866ed9c4ecb707cbf3889de42/lib/minitest/assertions.rb#L203

README.adoc Outdated Show resolved Hide resolved
@bbatsov

This comment has been minimized.

Copy link
Collaborator

commented Aug 8, 2019

Great starting point! I'm guessing we can create a bunch of related rules about other specialized assertion methods.

@koic koic force-pushed the koic:assert_nil branch from bf64848 to c189f9c Aug 8, 2019

Add "Assert Nil" rule
Use `assert_nil` if expecting `nil`.

```ruby
# bad
assert_equal(nil, actual)

# good
assert_nil(actual)
```

This rule prevents the following MT6's deprecated warning:

```ruby
class ExampleTest < Minitest::Test
  def test_expecting_nil
    foo = nil

    assert_equal(nil, foo)
  end
end
```

```console
% bundle exec rake test
Run options: --seed 16727

# Running:

DEPRECATED: Use assert_nil if expecting nil from
/Users/koic/src/github.com/rubocop-hq/rubocop-minitest/test/rubocop/minitest_test.rb:13. This
will fail in Minitest 6.
```

https://github.com/seattlerb/minitest/blob/ab39d35fb4e84eb866ed9c4ecb707cbf3889de42/lib/minitest/assertions.rb#L203

@koic koic force-pushed the koic:assert_nil branch from c189f9c to a0afd37 Aug 8, 2019

@bbatsov bbatsov merged commit 1118142 into rubocop-hq:master Aug 8, 2019

@koic koic deleted the koic:assert_nil branch Aug 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.