Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-4rspecrspec3

RSpec for Custom Validation


I have custom validations in rails model:

validate :custom_validation_method

def custom_validation_method
  # do stuff here
end

How can I make RSpec for this? Thanks!


Solution

  • To test validations(any)

    describe MyClass do
      it '#custom_validation' do
        expect(subject.valid?).to be_falsey
        #do stuff to subject to make it valid
        expect(subject.valid?).to be_truthy
      end
    end