Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RSpec matcher for validates_with
# RSpec matcher for validates_with.
# Usage:
# describe User do
# it { should validate_with CustomValidator }
# end
RSpec::Matchers.define :validate_with do |validator|
match do |subject| validator
description do
"RSpec matcher for validates_with"
failure_message_for_should do |text|
"expected to validate with #{validator}"
failure_message_for_should_not do |text|
"do not expected to validate with #{validator}"
Copy link

Bartuz commented Dec 1, 2015

changed deprecated methods and added chaining for options hash

it { validate_with(MyValidator).with_options(on: :admin) }

Copy link

rdh commented Jul 30, 2017

Just FYI, I've included this in my personal gem of spec helpers ... ... 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