Use the expect block syntax using the raise_error
matcher:
it "raises an exception" do
expect{ post(:create, {}) }.to raise_error ActionController::ParameterMissing
end
The reason that your code doesn't work is that post(:create, {})
raises the exception. This happens before the expect(response).to ...
code gets executes. Since the #post
message is not in a begin...end
block, the raised exception is passed up to RSpec failing the test.