对oauth提供者进行Rspec测试

我正在编写一个也是OAuth提供商的API。有没有推荐的方法来编写你的rspec测试? 启用oauth以保护所有端点后,如何编写将通过身份验证步骤的rspec测试?     
已邀请:
如果您使用的是oauth和oauth-plugin宝石,这篇文章可能对您有所帮助: http://peachshake.com/2010/11/11/oauth-capybara-rspec-headers-and-a-lot-of-pain/ 然而,oauth-plugin gem生成一些规范,其中包括帮助您模拟身份验证过程的帮助程序。 看看这个文件: https://github.com/pelle/oauth-plugin/blob/v0.4.0.pre4/lib/generators/rspec/templates/controller_spec_helper.rb 您可以使用以下方法签署您的请求:
def sign_request_with_oauth(token=nil,options={})
  ActionController::TestRequest.use_oauth=true
  @request.configure_oauth(current_consumer,token,options)
end

def two_legged_sign_request_with_oauth(consumer=nil,options={})
  ActionController::TestRequest.use_oauth=true
  @request.configure_oauth(consumer,nil,options)
end

def add_oauth2_token_header(token,options={})
  request.env['HTTP_AUTHORIZATION'] = "OAuth #{token.token}"
end
我建议您将此文件复制为规范的帮助程序,并根据您的需要进行修改。     

要回复问题请先登录注册