0

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

Agazoom
  • 618
  • 4
  • 19

1 Answers1

2

Try this:

Vin.any_instance.stub(:save).and_return(false)
Marcelo De Polli
  • 28,123
  • 4
  • 37
  • 47