Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Make assert_match behave consistently with test-unit version #117

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Currently, minitest's assert_match uses the #=~ method of the pattern, passing the object. This is inconsistent with test-unit (which does it the other way around), and also inconvenient when working with objects that have unusual implementations for #=~.

Notably, Mail::Body objects in mikel lindsaar's mail gem (https://github.com/mikel/mail/blob/master/lib/mail/body.rb, line 84) have an interesting #=~; the Mail::Body decodes itself before attempting to match. This has the convenient side effect of enabling the user to run assert_match against email bodies directly, without decoding them first.

The current implementation is limited to relying on Regexp#=~, so tricks like the one mikel pulled to make the user's life easier aren't possible. I also think there's value in not changing the behavior from test-unit's, for users upgrading from 1.8 to 1.9 and switching from test-unit to minitest.

Adjusted assert_match to behave like test-unit
This also enables matching against objects with unusual match methods,
most notably Mail::Body objects from the mail gem.

@ghost ghost assigned zenspider Apr 25, 2012

Owner

zenspider commented May 2, 2012

This is an intentional difference. We're expecting calls to be of the form:

assert_match matcher, matchee

where matcher has an implementation of #=~, not the matchee. In the case of mikel's code, you'd write:

assert_match re, mail_thingy

and Regexp#=~ will take it from there.

I've removed the second String check, so this should work. I've added an extra test to ensure that "unusual" objects that just implement to_str work properly as the matchee.

I've also made symmetric changes for refute_match.

P.S. Don't mess with another man's coding style.

@zenspider zenspider closed this May 2, 2012

@zenspider zenspider locked and limited conversation to collaborators May 17, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.