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