Skip to content

Instantly share code, notes, and snippets.

@tmilewski
Created February 10, 2011 15:11
Show Gist options
  • Save tmilewski/820666 to your computer and use it in GitHub Desktop.
Save tmilewski/820666 to your computer and use it in GitHub Desktop.
Verbose be_valid RSpec matcher
RSpec::Matchers.define :be_valid do
match do |model|
model.valid?
end
failure_message_for_should do |model|
"expected valid? to return true, got false:\n #{model.errors.full_messages.join("\n ")}"
end
failure_message_for_should_not do |model|
"expected valid? to return false, got true"
end
description do
"be valid"
end
end
1) Video while creating should be valid
Failure/Error: @video.should be_valid
expected valid? to return true, got false due to the following errors:
Youtube url is invalid
Youtube url can't be blank
# ./spec/models/video_spec.rb:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment