Created
July 14, 2011 02:00
-
-
Save fnando/1081807 to your computer and use it in GitHub Desktop.
RSpec matcher
This file contains 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
RSpec::Matchers.define :allow do |*values| | |
match do |record| | |
values.collect {|value| | |
record.send("#{@attribute}=", value) | |
record.valid? | |
record.errors[@attribute].empty? | |
}.all? | |
end | |
chain :as do |attribute| | |
@attribute = attribute | |
end | |
failure_message_for_should do |record| | |
"expected #{record.inspect} to allow each of #{values.inspect} as #{@attribute.inspect} value" | |
end | |
failure_message_for_should_not do |record| | |
"expected #{record.inspect} to reject each of #{values.inspect} as #{@attribute.inspect} value" | |
end | |
description do | |
"allow #{values.inspect} values for #{@attribute.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment