In my Rails application I am doing a unit test where I expect an error when calling a certain method.
test "sending a logout request while not logged should not return an error" do
assert_nothing_raised do
do_a_logout
end
end
Problem is that the test keeps reporting as Error instead as of Failure when do_a_logout
errors out.
The error is NoMethodError: NoMethodError: undefined method 'forget' for nil:NilClass
It comes from this method two or three levels below the do_a_logout
call
def forget user
user.forget
cookies.delete :user_id
cookies.delete :remember_token
end
Here, the error I am expecting is for user
to be nil and fail when calling forget
. How can I make the test report a Failure instead of an Error?