RecordNotFound raised when using find_by_id to get non-existent record in RSpec
问题 I've written this spec in products_controller_spec.rb, that is intended to test a redirect when destroy is called on a non-existent record: it "deleting a non-existent product should redirect to the user's profile page with a flash error" do delete :destroy, {:id => 9999} response.should redirect_to "/profile" flash[:error].should == I18n.t(:slideshow_was_not_deleted) end Here's the controller action in products_controller.rb: def destroy product = Product.find_by_id(params[:id]) redirect_to