Ruby on rails 带有API密钥的RSpec请求规范

Ruby on rails 带有API密钥的RSpec请求规范,ruby-on-rails,ruby,api,testing,rspec,Ruby On Rails,Ruby,Api,Testing,Rspec,我在这上面找不到任何东西。如何在RSpec请求测试中传递API密钥 我的API密钥以头的形式发送,因此我在web中像这样传递它: Header: Authorization Value: Token token="c32a29a71ca5953180c0a60c7d68ed9e" 如何在RSpec请求规范中传递它 谢谢 编辑: 这是我的规格: require 'spec_helper' describe "sessions" do before do @program =Fact

我在这上面找不到任何东西。如何在RSpec请求测试中传递API密钥

我的API密钥以头的形式发送,因此我在web中像这样传递它:

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

所以我非常接近。我需要记录实际API调用的输出,以查看服务器对HTTP头的确切格式。所以,问题是格式有点不合适

describe "sessions" do
  before do
    @user = FactoryGirl.create(:user)
    @api_key = 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=\"#{@api_key.access_token}\"" }
    response.status.should be(201)
  end
end
正如您所看到的,我必须将格式从:
{'Authorization'=>“Token-Token='MyString'”}
更改为
{“HTTP\u-Authorization”=>“Token-Token=\\”{@api\u-key.access\u-Token}\\\”


我还将
'MyString'
替换为对api令牌的实际实例的更健壮的引用
@api\u key.访问\u令牌

你能分享你的规格吗?这取决于你如何称呼事物。当然!我刚把它们贴出来。第一个规范失败,返回状态代码
401