Skip to content

Instantly share code, notes, and snippets.

@re5et
Forked from otaviomedeiros/validate_with_matcher.rb
Created August 27, 2013 20:15
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 re5et/6358575 to your computer and use it in GitHub Desktop.
Save re5et/6358575 to your computer and use it in GitHub Desktop.
# RSpec matcher for validates_with.
# https://gist.github.com/2032846
# Usage:
#
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |validator, options = {}|
match do |subject|
subject.class.validators.select do |candidate|
candidate == validator && candidate.options == options
end
end
description do
"RSpec matcher for validates_with"
end
failure_message_for_should do |text|
"expected to validate with #{validator}"
end
failure_message_for_should_not do |text|
"do not expected to validate with #{validator}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment