Created
April 11, 2014 07:49
-
-
Save yelled3/10447754 to your computer and use it in GitHub Desktop.
Rspec: Negation Matcher - description_when_negated
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
expect([1, 2, 3]).to ~include(3) | |
class Negation < BaseMatcher | |
def failure_message | |
matcher.failure_message_when_negated | |
end | |
end | |
class Include < BaseMatcher | |
def failure_message_when_negated | |
improve_hash_formatting(super) # this is the issue | |
end | |
def description_when_negated | |
"not #{description}" # or what ever you like... | |
end | |
end | |
class BaseMatcher | |
def failure_message_when_negated | |
assert_ivars :@actual | |
if respond_to?(:description_when_negated) | |
"expected #{@actual.inspect} to #{description_when_negated}" | |
else | |
"expected #{@actual.inspect} to not #{description}" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment