我在Rails 3.1中使用最新的oauth-plugin。我想用rspec测试来测试我的OAuth2 API控制器。在尝试了许多事情来授权我的请求之后,我只想简化认证过滤器以摆脱任何身份验证问题。但我仍然收到一个401 Unauthorized。为什么??使用oauth-plugin gem在rspec测试中测试OAuth2请求
users_controller.rb:
class UsersController
oauthenticate
def update
<do something>
end
end
users_controller_spec.rb:
describe UsersController do
describe "POST 'update'" do
before :each do
controller.stub!(:oauthenticate).and_return true
end
it "should be a successful request" do
post :update, { "user_id" => "some id" }
response.should be_ok
end
end
预期的ActionController :: TestResponse有200响应代码,但得到401
Rspec testing for oauth provider没有按”帮助。随着黄瓜测试一切正常,当设置一个有效的访问令牌授权标题。