Created
March 14, 2012 00:05
-
-
Save otaviomedeiros/2032846 to your computer and use it in GitHub Desktop.
RSpec matcher for validates_with
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
# 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| | |
match do |subject| | |
subject.class.validators.map(&:class).include? validator | |
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 |
Just FYI, I've included this in my personal gem of spec helpers ... https://github.com/schrodingersbox/spec_cat#credits ... please open an issue if you object or would like any changes to the attribution.
And thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
changed deprecated methods and added chaining for options hash https://gist.github.com/Bartuz/98abc9301adbc883b510
it { is_expected.to validate_with(MyValidator).with_options(on: :admin) }