ruby-on-rails-3之参数数量错误(0 代表 1)(ArgumentError)
jackei
阅读:27
2024-02-06 11:00:25
评论:0
我正在使用 devise
作为身份验证系统并创建了一个场景。
Scenario: Home page have a login page
When I go to the home page
And user is not logged in
Then I should see "Sign In"
用于步骤定义
When /^user is not logged in$/ do
signed_in? == false
end
我还在 cucumber 世界中添加了设计助手。
World(Devise::Controllers::Helpers)
cucumber 产生了这个错误:
And user is not logged in # features/step_definitions/web_steps.rb:260
wrong number of arguments (0 for 1) (ArgumentError)
./features/step_definitions/web_steps.rb:261:in `/^user is not logged in$/'
features/manage_home_page.feature:13:in `And user is not logged in'
为什么会产生它以及如何修复它?
更新
signed_in?
的定义方法是
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
def signed_in?(scope=nil)
[ scope || Devise.mappings.keys ].flatten.any? do |scope|
warden.authenticate?(:scope => scope)
end
end
它在设计中定义,我通过编写此代码将帮助程序添加到 cucumber
World(Devise::Controllers::Helpers)
进入 cucumber 的paths.rb文件。
请您参考如下方法:
试试这个
When /^user is not logged in$/ do
user_signed_in?.should be_false
end
更新
我认为你需要做这样的事情
When /^user is not logged in$/ do |user|
#check here user not logged in
end
或者
您可以尝试将您的功能修改为
Scenario: Home page has a login page
Given I am on the home page
And I am not logged in
Then I should see "Sign In"
然后在步骤中
Given /^user is not logged in$/ do
visit('users/sign_out') # this will ensure that the user is not logged in
end
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。