参数数量错误(0 代表 1)(ArgumentError)
我使用 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
我还向黄瓜世界添加了 Devise 助手。
World(Devise::Controllers::Helpers)
黄瓜正在生成此错误:
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
在 Devise 中定义的,我通过将此代码 World(Devise::Controllers::Helpers)
写入 cucumber 的路径来将该助手添加到 cucumber .rb 文件。
I am using devise
as an authentication system and created a scenario.
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"
for step definition
When /^user is not logged in$/ do
signed_in? == false
end
i had also added Devise helpers to the cucumber world.
World(Devise::Controllers::Helpers)
and cucumber is generating this error:
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'
Why is it generating and how to fix it?
Update
the definition of signed_in?
method is
# 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
its defined in Devise and i added that helper to cucumber by writing this code World(Devise::Controllers::Helpers)
into cucumber's paths.rb file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
更新
我认为你需要做这样的事情
或者
的功能修改为“然后”
您可以尝试将步骤中
Try this instead
UPDATED
I think you need to do something like this
or
You could try modifying your feature to
Then in the steps
我遇到了与此类似的问题,结果证明测试行与代码中其他位置的另一个步骤定义相匹配。
这里似乎不太可能,但是您还有其他可以匹配
And user is notlogin
但需要参数的内容吗?I've had problems similar to this which turned out to be the test line matching another step definition somewhere else in my code.
It seems unlikely here but do you have anything else which could match to
And user is not logged in
but which requires an argument?