Skip to content

Instantly share code, notes, and snippets.

@Peeja
Created October 8, 2008 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peeja/15604 to your computer and use it in GitHub Desktop.
Save Peeja/15604 to your computer and use it in GitHub Desktop.
module ValidationMatcher
class BeValid
def matches?(target)
@target = target
@target.valid?
end
def failure_message
"expected #{@target} to be valid, but:\n" +
@target.errors.map { |a, m| "- #{a.humanize} #{m} (#{a}: #{@target[a].inspect})" }.join("\n")
end
def negative_failure_message
"expected #{@target.inspect} not to be valid, but it was."
end
end
def be_valid
BeValid.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment