2010-04-09 09:23:41 +00:00
|
|
|
module Spec
|
|
|
|
module Rails
|
|
|
|
module Matchers
|
|
|
|
class BeValid #:nodoc:
|
|
|
|
|
|
|
|
def matches?(model)
|
|
|
|
@model = model
|
|
|
|
@model.errors.clear
|
|
|
|
@model.errors.empty? && @model.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def failure_message
|
|
|
|
"#{@model.class} expected to be valid but had errors:\n #{@model.errors.full_messages.join("\n ")}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def negative_failure_message
|
2010-07-23 20:09:54 +00:00
|
|
|
"#{@model.class} expected to be invalid but was valid.\n"
|
2010-04-09 09:23:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
"be valid"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def be_valid
|
|
|
|
BeValid.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|