这是我的代码:
before(:each) do
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(api_key.access_token)
end
我的测试本应通过,但显示此错误:
Failure/Error: request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials("#{api_key.access_token}")
ArgumentError:
wrong number of arguments (0 for 1..2)
gem :
rspec-rails 版本 = 2.14.1。
rails verison = 4
来自 'git://github.com/mongoid/mongoid.git' 的 mongoid
最佳答案
您在测试中访问的request
方法记录在http://rubydoc.info/gems/rack-test/0.6.2/Rack/Test/Session:request并期望 1 或 2 个参数如错误所示。您在 request.env
上收到错误,因为您正在调用没有参数的 request
。
关于ruby-on-rails - Rspec request.env 参数数量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21685892/