Reputation: 618
I have the following action in my controller:
def create
@user = current_user
@vin = @user.vins.new(params[:vin])
if @vin.save
# waiting for implementation
logger.debug("here we are")
else
redirect_to(vins_path)
end
end
I'd like to test with with rspec. However, I want to stub out the save operation to simulate a failure:
it "should send user to vins_path if there is a problem creating the VIN" do
@vin.stub!(:save).and_return(false)
post 'create', :vin => { :name => "Test 1", :vin => "test" }
response.should redirect_to(vins_path)
end
However, the stub doesn't seem to work as the save operation is always successful. What am I doing wrong?
Thanks
Upvotes: 0
Views: 276
Reputation: 29291
Try this:
Vin.any_instance.stub(:save).and_return(false)
Upvotes: 2