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:

       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

I get

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.

Need Your Help

value wont pass to controller from provider angularjs

javascript angularjs model-view-controller controller

So I have a controller and a provider which I am trying to pass a value from the provider to the controller, nothing too complex. I have been through several tuts and forum threads about this but n...

Extract dates, times and date ranges from text in PHP

php regex date

I'm building a local events calendar which takes RSS feeds and website scrapes and extracts event dates from them.