Created
August 24, 2013 19:03
-
-
Save barelyknown/6329879 to your computer and use it in GitHub Desktop.
Rspec matcher to test if a class initialize valid instances.
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
# test if ActiveRecord classes (or ActiveModel) initialize valid instances | |
# it { should initialize_as_a_valid_instance } | |
RSpec::Matchers.define :initialize_as_a_valid_instance do | |
match do |actual| | |
actual.valid? | |
end | |
description do | |
"initialize as a valid #{actual.class.to_s} instance" | |
end | |
failure_message_for_should do |text| | |
"expected object to initialize as a valid instance but it has errors: " + | |
actual.errors.full_messages.join(", ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment