Ignore the validation failures in rspec
I need to test a callback that's run before_validation, but as I want to test only the callback I don't want test to fail when validation fails, and at the moment I get:
ActiveRecord::RecordInvalid: Validation failed: Preview Invalid video ID
I've tried out a lot of stuff. I believe that my callback method is not called when using .save(:validate => false) because it runs on before_validation.
But when I do something like this:
show = FactoryGirl.build :show show.should_receive :parse_url show.save
Failure/Error: show.should_receive :parse_url (#<Show:0x007fd9954699e0>).parse_url(any args) expected: 1 time received: 0 times
despite my code in the model:
before_validation :parse_url, :on => :save
Also beside the method call I want to check the fields after they were formatted.
I'll be very thankful for any help.
Well, you can always just catch the ActiveRecord::RecordInvalid error when it fires, and yet still test the behaviour of your before_validation. Because you catch the error, the RSpec test won't fail.