How to replicate rescue on rspec

Posted: January 23, 2008 in RESTful, RSpec, RUBY, Ruby on Rails
Tags: , , , , ,

So you like using rescue_from method? Some of my friends asked me how to replicate rescue on rspec :-) The answer is simple

Put this before your call to its rescue:

@contact_request.errors.stub!(:full_messages).and_return([])

and then put this inside your related it or specify, for example :

@contact_request.should_receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(@contact_request))

Done!

tinggalkan feedback konstruktif atau lebih baik diam

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s