我正在尝试为我的API编写请求规范,但需要传递API密钥。 API密钥作为标题传递。在Web从我通过这样的:如何在需要API密钥时测试请求规范
Header: Authorization
Value: Token token="MyString"
在我的天赋,我想这样的:
describe "sessions" do
before do
FactoryGirl.create(:api_key)
end
it "is authenticated with a token" do
put "/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authentication_token}", {user: {name: "New Name"}}, { 'HTTP_AUTHORIZATION' => "Token token=\"MyString\"" }
response.status.should be(201)
end
end
这并不引发异常,但它也不起作用。我的测试只是失败,错误代码401
我将它改为:'put“/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authenti cation_token}”,{user :{name:“New Name”}},{'HTTP_AUTHORIZATION'=>“Token token ='MyString'”}'但我在测试中仍然收到了'401'响应。 – Arel