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.
Merge pull request rubocop#231 from fatkodima/ignore-test-methods-wit…
…h-arguments Do not treat `test_` methods with arguments as test methods
- Loading branch information
Showing
4 changed files
with
59 additions
and
2 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 @@ | ||
* [#231](https://github.com/rubocop/rubocop-minitest/pull/231): Change what is considered a test case by `rubocop-minitest` (`public` method without arguments with `test_` name prefix). ([@fatkodima][]) |
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
50 changes: 50 additions & 0 deletions
50
test/rubocop/cop/mixin/minitest_exploration_helpers_test.rb
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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class MinitestExplorationHelpersTest < Minitest::Test | ||
module Helper | ||
extend RuboCop::Cop::MinitestExplorationHelpers | ||
class << self | ||
public :test_case? | ||
end | ||
end | ||
|
||
SOURCE = <<~RUBY | ||
class FooTest < Minitest::Test | ||
def not_test_case; end | ||
def test_with_arguments(arg); end | ||
def test_public; end | ||
protected | ||
def test_protected; end | ||
private | ||
def test_private; end | ||
end | ||
RUBY | ||
|
||
def test_test_case_returns_true_for_test_case | ||
assert Helper.test_case?(method_node(:test_public)) | ||
end | ||
|
||
def test_test_case_returns_false_for_hidden_test_methods | ||
refute Helper.test_case?(method_node(:test_protected)) | ||
refute Helper.test_case?(method_node(:test_private)) | ||
end | ||
|
||
def test_test_case_returns_false_for_non_test_methods | ||
refute Helper.test_case?(method_node(:non_test_case)) | ||
end | ||
|
||
def test_test_case_returns_false_for_test_methods_with_arguments | ||
refute Helper.test_case?(method_node(:test_with_arguments)) | ||
end | ||
|
||
private | ||
|
||
def method_node(method_name) | ||
class_node = parse_source!(SOURCE).ast | ||
class_node.body.each_child_node(:def).find { |def_node| def_node.method?(method_name) } | ||
end | ||
end |