Skip to content

Instantly share code, notes, and snippets.

@yelled3
Created April 11, 2014 07:49
Show Gist options
  • Save yelled3/10447754 to your computer and use it in GitHub Desktop.
Save yelled3/10447754 to your computer and use it in GitHub Desktop.
Rspec: Negation Matcher - description_when_negated
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