-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Do not treat test_
methods with arguments as test methods
#231
Do not treat test_
methods with arguments as test methods
#231
Conversation
Makes sense! AFAIK, the conditions of the test method are as follows:
Can you add a test code and changelog entry? |
e7cea32
to
b5a5723
Compare
Added a test code and changelog entry. I decided to extract test cases into a separate file instead of dumping into some random cop test file. Is it ok? |
end | ||
RUBY | ||
|
||
def test_test_case_p_returns_true_for_test_case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the p
mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"predicate". It's a replacement for ?
at the end of the method name. I saw this convention in the ruby source code. For example, https://github.com/ruby/ruby/blob/a9bcc058bb4cd954e8406c93debb876983627ca9/array.c#L8851.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if p
is used in the product code, the test_
descriptions might be easier to understand with predicate
.
On a side note, p
reminds me of LISP :-)
def test_test_case_p_returns_false_for_test_methods_with_arguments | ||
refute Helper.test_case?(method_node(SOURCE, :test_with_arguments)) | ||
end | ||
|
||
private | ||
|
||
def method_node(source, method_name) | ||
class_node = parse_source!(source).ast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be reduced to the single argument. The entire place where SOURCE
is used.
def test_test_case_p_returns_false_for_test_methods_with_arguments | |
refute Helper.test_case?(method_node(SOURCE, :test_with_arguments)) | |
end | |
private | |
def method_node(source, method_name) | |
class_node = parse_source!(source).ast | |
def test_test_case_p_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 |
@@ -43,6 +44,10 @@ def test_cases(class_node) | |||
test_cases + test_blocks | |||
end | |||
|
|||
def test_case_signature?(def_node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_method?
might be better, AFAIK signature doesn't include scope.
def test_case_signature?(def_node) | |
def test_method?(def_node) |
b5a5723
to
2400514
Compare
Updated with the suggestions. |
Thanks! |
While testing #229 on https://github.com/openstreetmap/openstreetmap-website, it detected this - https://github.com/openstreetmap/openstreetmap-website/blob/b278bc06ef720af8c21c99659c4d70334384c386/test/integration/oauth2_test.rb#L141, because
rubocop-minitest
detects all class methods starting withtest_
as test cases. But we should ignore such methods having arguments.