3
我在这找不到任何东西。我如何在RSpec请求测试中传递API密钥?使用API密钥的RSpec请求规格
我的API密钥是在标头中发送,所以我将它传递这样的网站:
Header: Authorization
Value: Token token="c32a29a71ca5953180c0a60c7d68ed9e"
我如何把它传递在一个RSpec要求规范?
谢谢!
编辑:
这里是我的规格:
require 'spec_helper'
describe "sessions" do
before do
@program =FactoryGirl.create(:program)
@user = FactoryGirl.create(:user)
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"}}, { 'Authorization' => "Token token='MyString'" }
response.status.should be(201)
end
it "fails without an API Token" do
put "/api/v1/users/#{@user.id}?user_email=#{@user.email}&auth_token=#{@user.authentication_token}", user: {name: "New Name"}
response.status.should be(401)
end
end
你能分享你的规格吗?这取决于你如何称呼事情。 – muttonlamb
当然可以!我刚刚发布了它们。第一个规范失败了,返回一个状态码“401” – Arel