Created
November 22, 2012 01:06
-
-
Save willnet/4128831 to your computer and use it in GitHub Desktop.
valid attribute custom matcher for minitest
This file contains hidden or 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
| class ValidAttributeMatcher | |
| def initialize(attr_name) | |
| @attr_name = attr_name | |
| end | |
| def matches?(subject) | |
| @subject = subject | |
| @subject.valid? | |
| @subject.errors[@attr_name].empty? | |
| end | |
| def failure_message_for_should | |
| "expected to valid ##{@attr_name} but #{@subject.errors[@attr_name]}" | |
| end | |
| def failure_message_for_should_not | |
| "expected to invalid ##{@attr_name} but valid" | |
| end | |
| end | |
| MiniTest::Unit::TestCase.register_matcher ValidAttributeMatcher, :have_valid_attribute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment