Skip to content
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

Enhance AssertMatch/RefuteMatch to check match? and =~ methods #240

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

fatkodima
Copy link
Contributor

Closes #239.

@@ -24,7 +24,8 @@ module MinitestCopRule
# @api private
#
def define_rule(assertion_method, target_method:, preferred_method: nil, inverse: false)
preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}" if preferred_method.nil?
target_methods = Array(target_method)
preferred_method = "#{assertion_method}_#{target_methods.first.to_s.delete('?')}" if preferred_method.nil?
Copy link
Member

@koic koic Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be confusing to see the special treatment of the first element. So, the order of the array shouldn't matter for API user.

Perhaps it would be preferable to require preferred_method optional param if more than one element is specified. It might be helpful to add it to the documentation and throw an exception message if it was not specified the option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Added a check and updated the docs.

@fatkodima fatkodima force-pushed the assert_refute-match-more-methods branch from 7a7dde6 to 33c35e8 Compare February 13, 2023 13:28
preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}" if preferred_method.nil?
target_methods = Array(target_method)
if target_methods.size > 1 && preferred_method.nil?
raise ArgumentError, 'preferred_method should be provided if using more than one target methods'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tweak it?

Suggested change
raise ArgumentError, 'preferred_method should be provided if using more than one target methods'
raise ArgumentError, '`:preferred_method` keyword argument must be used if using more than one target methods.'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@fatkodima fatkodima force-pushed the assert_refute-match-more-methods branch from 33c35e8 to d871dcd Compare February 14, 2023 15:26
@koic koic merged commit a866b2d into rubocop:master Feb 14, 2023
@koic
Copy link
Member

koic commented Feb 14, 2023

Thanks!

@fatkodima fatkodima deleted the assert_refute-match-more-methods branch February 14, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minitest/AssertMatch behavior doesn't match style guide
2 participants