RSpec FAIL – Testing Rails ‘destroy’

I’m writing some specs for Citrulu and was scratching my head about this one for a while:

When writing specs for Controllers, some http methods accept a hash as an input:

it "assigns the requested test_file as @test_file" do
  controller.stub(:check_ownership!)
  get :edit, {:id => @test_file.to_param}
  assigns(:test_file).should eq(@test_file)
end

However with delete, this doesn’t work – the following fails to call the destroy action:

it "Calls 'delete!' on the model" do
  TestFile.any_instance.should_receive(:delete!)
  delete :destroy, {id: @test_file.to_param}, format: 'js'
end

The correct syntax is to pass id: as a parameter instead of a hash:

it "Calls 'delete!' on the model" do
  TestFile.any_instance.should_receive(:delete!)
  delete :destroy, id: @test_file.to_param, format: 'js'
end
Comments are closed.