Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.2 |
- |
This cop enforces the test to use assert_empty
instead of using assert(object.empty?)
.
# bad
assert(object.empty?)
assert(object.empty?, 'message')
# good
assert_empty(object)
assert_empty(object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.5 |
0.11 |
This cop enforces the test to use assert_empty
instead of using assert_equal([], object)
or assert_equal({}, object)
.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.4 |
- |
This cop enforces the use of assert_equal(expected, actual)
over assert(expected == actual)
.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use assert_in_delta
instead of using assert_equal
to compare floats.
# bad
assert_equal(0.2, actual)
assert_equal(0.2, actual, 'message')
# good
assert_in_delta(0.2, actual)
assert_in_delta(0.2, actual, 0.001, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.2 |
- |
This cop enforces the test to use assert_includes
instead of using assert(collection.include?(object))
.
# bad
assert(collection.include?(object))
assert(collection.include?(object), 'message')
# good
assert_includes(collection, object)
assert_includes(collection, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.4 |
- |
This cop enforces the test to use assert_instance_of(Class, object)
over assert(object.instance_of?(Class))
.
# bad
assert(object.instance_of?(Class))
assert(object.instance_of?(Class), 'message')
# good
assert_instance_of(Class, object)
assert_instance_of(Class, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use assert_kind_of(Class, object)
over assert(object.kind_of?(Class))
.
# bad
assert(object.kind_of?(Class))
assert(object.kind_of?(Class), 'message')
# good
assert_kind_of(Class, object)
assert_kind_of(Class, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.6 |
- |
This cop enforces the test to use assert_match
instead of using assert(matcher.match(string))
.
# bad
assert(matcher.match(string))
assert(matcher.match(string), 'message')
# good
assert_match(regex, string)
assert_match(matcher, string, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.1 |
- |
This cop enforces the test to use assert_nil
instead of using
assert_equal(nil, something)
, assert(something.nil?)
, or assert_predicate(something, :nil?)
.
# bad
assert_equal(nil, actual)
assert_equal(nil, actual, 'message')
assert(object.nil?)
assert(object.nil?, 'message')
assert_predicate(object, :nil?)
assert_predicate(object, :nil?, 'message')
# good
assert_nil(actual)
assert_nil(actual, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.10 |
- |
This cop checks for opportunities to use assert_output
.
# bad
$stdout = StringIO.new
puts object.method
$stdout.rewind
assert_match expected, $stdout.read
# good
assert_output(expected) { puts object.method }
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use assert_path_exists
instead of using assert(File.exist?(path))
.
# bad
assert(File.exist?(path))
assert(File.exist?(path), 'message')
# good
assert_path_exists(path)
assert_path_exists(path, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.18 |
- |
This cop enforces the test to use assert_predicate
instead of using assert(obj.a_predicate_method?)
.
# bad
assert(obj.one?)
assert(obj.one?, 'message')
# good
assert_predicate(obj, :one?)
assert_predicate(obj, :one?, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.3 |
- |
This cop enforces the use of assert_respond_to(object, :do_something)
over assert(object.respond_to?(:do_something))
.
# bad
assert(object.respond_to?(:do_something))
assert(object.respond_to?(:do_something), 'message')
assert(respond_to?(:do_something))
# good
assert_respond_to(object, :do_something)
assert_respond_to(object, :do_something, 'message')
assert_respond_to(self, :do_something)
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use assert_silent { … }
instead of using assert_output('', '') { … }
.
# bad
assert_output('', '') { puts object.do_something }
# good
assert_silent { puts object.do_something }
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.2 |
- |
This cop enforces the test to use assert(actual)
instead of using assert_equal(true, actual)
.
# bad
assert_equal(true, actual)
assert_equal(true, actual, 'message')
# good
assert(actual)
assert(actual, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
No |
No |
0.11 |
- |
This cop tries to detect when a user accidentally used
assert
when they meant to use assert_equal
.
This cop is unsafe because it is not possible to determine
whether the second argument of assert
is a message or not.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.10 |
- |
This cop checks for usage of assertions in lifecycle hooks.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.19 |
- |
If a Minitest class inherits from another class, it will also inherit its methods causing Minitest to run the parent’s tests methods twice.
This cop detects when there are two tests classes, one inherits from the other, and both have tests methods. This cop will add an offense to the Child class in such a case.
# bad
class ParentTest < Minitest::Test
def test_parent # it will run this test twice.
end
end
class ChildTest < ParentTest
def test_child
end
end
# good
class ParentTest < Minitest::Test
def test_parent
end
end
class ChildTest < Minitest::Test
def test_child
end
end
# good
class ParentTest < Minitest::Test
end
class ChildTest
def test_child
end
def test_parent
end
end
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.7 |
0.16 |
This cop checks for deprecated global expectations and autocorrects them to use expect format.
# bad
musts.must_equal expected_musts
wonts.wont_match expected_wonts
musts.must_raise TypeError
expect(musts).must_equal expected_musts
expect(wonts).wont_match expected_wonts
expect { musts }.must_raise TypeError
value(musts).must_equal expected_musts
value(wonts).wont_match expected_wonts
value { musts }.must_raise TypeError
# good
_(musts).must_equal expected_musts
_(wonts).wont_match expected_wonts
_ { musts }.must_raise TypeError
# bad
musts.must_equal expected_musts
wonts.wont_match expected_wonts
musts.must_raise TypeError
# good
_(musts).must_equal expected_musts
_(wonts).wont_match expected_wonts
_ { musts }.must_raise TypeError
expect(musts).must_equal expected_musts
expect(wonts).wont_match expected_wonts
expect { musts }.must_raise TypeError
value(musts).must_equal expected_musts
value(wonts).wont_match expected_wonts
value { musts }.must_raise TypeError
# bad
musts.must_equal expected_musts
wonts.wont_match expected_wonts
musts.must_raise TypeError
_(musts).must_equal expected_musts
_(wonts).wont_match expected_wonts
_ { musts }.must_raise TypeError
value(musts).must_equal expected_musts
value(wonts).wont_match expected_wonts
value { musts }.must_raise TypeError
# good
expect(musts).must_equal expected_musts
expect(wonts).wont_match expected_wonts
expect { musts }.must_raise TypeError
# bad
musts.must_equal expected_musts
wonts.wont_match expected_wonts
musts.must_raise TypeError
_(musts).must_equal expected_musts
_(wonts).wont_match expected_wonts
_ { musts }.must_raise TypeError
expect(musts).must_equal expected_musts
expect(wonts).wont_match expected_wonts
expect { musts }.must_raise TypeError
# good
value(musts).must_equal expected_musts
value(wonts).wont_match expected_wonts
value { musts }.must_raise TypeError
Name | Default value | Configurable values |
---|---|---|
EnforcedStyle |
|
|
Include |
|
Array |
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces correct order of expected and
actual arguments for assert_equal
.
# bad
assert_equal foo, 2
assert_equal foo, [1, 2]
assert_equal foo, [1, 2], 'message'
# good
assert_equal 2, foo
assert_equal [1, 2], foo
assert_equal [1, 2], foo, 'message'
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.10 |
- |
This cop checks if test cases contain too many assertion calls. The maximum allowed assertion calls is configurable.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Disabled |
Yes |
No |
0.12 |
- |
This cop checks if test cases contain any assertion calls.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.3 |
- |
This cop enforces to use refute_empty
instead of
using refute(object.empty?)
.
# bad
refute(object.empty?)
refute(object.empty?, 'message')
# good
refute_empty(object)
refute_empty(object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.3 |
- |
This cop enforces the use of refute_equal(expected, object)
over assert(expected != actual)
or assert(! expected == actual)
.
# bad
assert("rubocop-minitest" != actual)
assert(! "rubocop-minitest" == actual)
# good
refute_equal("rubocop-minitest", actual)
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.3 |
- |
This cop enforces the use of refute(object)
over assert_equal(false, object)
.
# bad
assert_equal(false, actual)
assert_equal(false, actual, 'message')
assert(!test)
assert(!test, 'message')
# good
refute(actual)
refute(actual, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use refute_in_delta
instead of using refute_equal
to compare floats.
# bad
refute_equal(0.2, actual)
refute_equal(0.2, actual, 'message')
# good
refute_in_delta(0.2, actual)
refute_in_delta(0.2, actual, 0.001, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.3 |
- |
This cop enforces the test to use refute_includes
instead of using refute(collection.include?(object))
.
# bad
refute(collection.include?(object))
refute(collection.include?(object), 'message')
# good
refute_includes(collection, object)
refute_includes(collection, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.4 |
- |
This cop enforces the use of refute_instance_of(Class, object)
over refute(object.instance_of?(Class))
.
# bad
refute(object.instance_of?(Class))
refute(object.instance_of?(Class), 'message')
# good
refute_instance_of(Class, object)
refute_instance_of(Class, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the use of refute_kind_of(Class, object)
over refute(object.kind_of?(Class))
.
# bad
refute(object.kind_of?(Class))
refute(object.kind_of?(Class), 'message')
# good
refute_kind_of(Class, object)
refute_kind_of(Class, object, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.6 |
- |
This cop enforces the test to use refute_match
instead of using refute(matcher.match(string))
.
# bad
refute(matcher.match(string))
refute(matcher.match(string), 'message')
# good
refute_match(matcher, string)
refute_match(matcher, string, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.2 |
- |
This cop enforces the test to use refute_nil
instead of using
refute_equal(nil, something)
, refute(something.nil?)
, or refute_predicate(something, :nil?)
.
# bad
refute_equal(nil, actual)
refute_equal(nil, actual, 'message')
refute(actual.nil?)
refute(actual.nil?, 'message')
refute_predicate(object, :nil?)
refute_predicate(object, :nil?, 'message')
# good
refute_nil(actual)
refute_nil(actual, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces the test to use refute_path_exists
instead of using refute(File.exist?(path))
.
# bad
refute(File.exist?(path))
refute(File.exist?(path), 'message')
# good
refute_path_exists(path)
refute_path_exists(path, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.18 |
- |
This cop enforces the test to use refute_predicate
instead of using refute(obj.a_predicate_method?)
.
# bad
refute(obj.one?)
refute(obj.one?, 'message')
# good
refute_predicate(obj, :one?)
refute_predicate(obj, :one?, 'message')
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Enabled |
Yes |
Yes |
0.4 |
- |
This cop enforces the test to use refute_respond_to(object, :do_something)
over refute(object.respond_to?(:do_something))
.
# bad
refute(object.respond_to?(:do_something))
refute(object.respond_to?(:do_something), 'message')
refute(respond_to?(:do_something))
# good
refute_respond_to(object, :do_something)
refute_respond_to(object, :do_something, 'message')
refute_respond_to(self, :do_something)
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
Yes |
0.10 |
- |
This cop enforces that test method names start with test_
prefix.
It aims to prevent tests that aren’t executed by forgetting to start test method name with test_
.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.14 |
- |
This cop checks for assert_raises
has an assertion method at
the bottom of block because the assertion will be never reached.
Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed |
---|---|---|---|---|
Pending |
Yes |
No |
0.10 |
- |
This cop checks for a specified error in assert_raises
.
# bad
assert_raises { raise FooException }
assert_raises('This should have raised') { raise FooException }
# good
assert_raises(FooException) { raise FooException }
assert_raises(FooException, 'This should have raised') { raise FooException }