【发布时间】:2014-02-10 19:14:44
【问题描述】:
这是我的代码:
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)
-
宝石:
rspec-rails 版本 = 2.14.1。
rails 版本 = 4
来自'git://github.com/mongoid/mongoid.git'的mongoid
【问题讨论】:
-
api_key 设置在哪里?
-
调用 ApiKey.create 有效吗?在每个块之前尝试 api_key = ApiKey.create ,看看这是否是引发错误的原因
-
你能在你的 Rails 控制台试试这个吗? ActionController::HttpAuthentication::Token.encode_credentials("anything")。它会抛出错误吗?
-
不确定发生了什么。通过使用 --backtrace 选项运行 rspec 来发布完整的错误消息
-
我会在您收到错误的那一行打印出
method(:request)和request.method(:env),以确保您正在调用您认为的request方法。
标签: ruby-on-rails rspec2 rspec-rails