I've seen post answering this for RSpec but I'm using minitest for testing. Does anyone know how to properly write the test below? Because currently it generates an error referring to its first test line:
NoMethodError: undefined method `cookies' for nil:NilClass
test "if already logged in" do
# To set two cookies
request.cookies["HTTP_EMAIL"] = @user1.email
request.cookies["Authorization"] = 'mytoken'
# Trying to log in as different user
log_in_as(@user2) # This uses a test helper that I already found works fine
# We should get back JSON
response.header['Content-Type'].should include 'application/json'
assert_response :success
# It should respond with a specific message
assert_select "fc", JSON.parse(response.body)["Already logged in"]
# Cookies should not have changed. Original user still logged in, not a new user
assert_equal cookies['HTTP_EMAIL'], @orguser_admin.email
assert_equal cookies['Authorization'], "mytoken"
end
Aucun commentaire:
Enregistrer un commentaire