forked from rubocop/rubocop-minitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes rubocop#216
- Loading branch information
1 parent
6e875c4
commit 543c5fe
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#216](https://github.com/rubocop/rubocop-minitest/issues/216): Add new `Minitest/NoTestCases` cop. ([@tejasbubane][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Minitest | ||
# Checks if test class contains any test cases. | ||
# | ||
# @example | ||
# # bad | ||
# class FooTest < Minitest::Test | ||
# def do_something | ||
# end | ||
# end | ||
# | ||
# # good | ||
# class FooTest < Minitest::Test | ||
# def test_something | ||
# assert true | ||
# end | ||
# end | ||
# | ||
class NoTestCases < Base | ||
include MinitestExplorationHelpers | ||
|
||
MSG = 'Test class should have test cases.' | ||
|
||
def on_class(node) | ||
return unless test_class?(node) | ||
|
||
add_offense(node) if test_cases(node).empty? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class NoTestCases < Minitest::Test | ||
def test_registers_offense_for_empty_test_class | ||
assert_offense(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test class should have test cases. | ||
end | ||
RUBY | ||
end | ||
|
||
def test_registers_offense_for_nonempty_test_class_with_no_test_cases | ||
assert_offense(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test class should have test cases. | ||
def perform | ||
1 + 2 | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
def test_does_not_register_offense_when_test_class_has_test_case | ||
assert_no_offenses(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
def test_foo; end | ||
end | ||
RUBY | ||
end | ||
|
||
def test_considers_active_support_test_example_format | ||
assert_no_offenses(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
test 'something' do; end | ||
end | ||
RUBY | ||
end | ||
|
||
def test_does_not_register_offense_for_non_test_classes | ||
assert_no_offenses(<<~RUBY) | ||
class FooTest | ||
def perform; end | ||
end | ||
RUBY | ||
end | ||
end |