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
bd380af
commit 37c2784
Showing
5 changed files
with
74 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 has no test cases.' | ||
|
||
def on_class(node) | ||
return unless test_class?(node) | ||
|
||
add_offense(node) unless test_cases(node).count.positive? | ||
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,32 @@ | ||
# 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 has no 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 has no test cases. | ||
def perform | ||
1 + 2 | ||
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 |