-
-
Notifications
You must be signed in to change notification settings - Fork 45
Check for assertion method receiver - fixes #321 #322
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
base: master
Are you sure you want to change the base?
Conversation
This is not the best solution. It will ignore all custom assertions the user may have written themselves, and test methods provided by gems like rails. I think it would be better to instead only look at methods that have no receiver. |
Apologies, I didn't see that tested for anywhere.
Or where the receiver is not a kind_of |
I guess the
Perhaps, but not decidable by rubocop. It can't tell if Please add a changelog entry for this, and write a meaningful commit message starting with |
Will take a 👀 |
end | ||
end | ||
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity | ||
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize |
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.
Can you refactor to the following and rebase with the latest master branch?
diff --git a/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb b/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
index 4bb7382..ceb1971 100644
--- a/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
+++ b/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
@@ -99,19 +99,20 @@ module RuboCop
end
end
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def assertion_method?(node)
return false unless node
+ return false if node.receiver
return assertion_method?(node.expression) if node.assignment? && node.respond_to?(:expression)
return false if !node.send_type? && !node.block_type? && !node.numblock_type?
ASSERTION_PREFIXES.any? do |prefix|
method_name = node.method_name
- (method_name.start_with?(prefix) && !node.receiver) || node.method?(:flunk)
+ method_name.start_with?(prefix) || node.method?(:flunk)
end
end
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def lifecycle_hook_method?(node)
node.def_type? && LIFECYCLE_HOOK_METHODS.include?(node.method_name)
@MatzFan Can you rebase with the latest master branch and apply the above comment? Finally, please squash your commits into one. |
Sorry I dropped the ball on this one. I've just tried to finish it off but the addition of the guard |
Counting assertions based on a string prefix of "assert_" or "refute_" is replaced by a symbol comparison against the 38 Minitest assertion methods.