RoR:参数数量错误

发布于 2024-11-01 11:26:57 字数 913 浏览 1 评论 0原文

我试图在 Rails 3 代码中调用一个方法,但得到:

失败/错误:集成登录错误用户 参数错误: 参数数量错误(0 代表 1)

这是调用代码(在 RSpec 帮助器中):

before(:each) do
    wrong_user = Factory(:user, :email => "[email protected]", :password=>"hellohello", :password_confirmation => "hellohello")
    integration_sign_in wrong_user
end

因此它显然传递了一个参数。如果参数由于某种原因为空,是否会认为它不是参数?

相关背景故事:为了测试,我刚刚从 webrat 切换到 capybara。按照 Railscast 257 中的建议,我还安装了 launchy 和 database_cleaner gem。当我使用 webrat 时,上面的代码按预期工作,但现在(我相信与database_cleaner相关)出了问题。

可能相关:在我的spec_helper.rb中我更改为: config.use_transactional_fixtures = false (即使“true”也有同样的问题)

有什么想法吗?谢谢。

I am trying to call a method in my Rails 3 code but am getting:

Failure/Error: integration_sign_in wrong_user
ArgumentError:
wrong number of arguments (0 for 1)

Here is the calling code (in an RSpec helper):

before(:each) do
    wrong_user = Factory(:user, :email => "[email protected]", :password=>"hellohello", :password_confirmation => "hellohello")
    integration_sign_in wrong_user
end

So it is clearly passing one argument. If the argument is null for some reason, would that make it consider it not a parameter?

RELEVANT BACKSTORY: For testing, I just switched from webrat to capybara. As suggested in Railscast 257, I also installed the launchy and database_cleaner gems. When I was using webrat, the code above worked as expected, but now (I believe related to database_cleaner) something is going wrong.

Possibly relevant: In my spec_helper.rb I changed to:
config.use_transactional_fixtures = false (even though 'true' has the same problem)

Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷雾森÷林ヴ 2024-11-08 11:26:57

看起来参数错误实际上并不在这个函数中(尽管堆栈的顶部使它看起来像这样。实际的错误在integration_sign_in函数内部:

def integration_sign_in(user)
        visit signin_path
        fill_in :email,    :with => user.email
        fill_in :password, :with => user.password
        click_button
    end

看起来click_button需要一个在 capybara 中存在争论,但在 webrat 中则不然。

It looks like the argument error was not actually in this function (even though the top of the stack makes it look like it is. The actual error is inside of the integration_sign_in function:

def integration_sign_in(user)
        visit signin_path
        fill_in :email,    :with => user.email
        fill_in :password, :with => user.password
        click_button
    end

It looks like click_button needs an argument in capybara, but it does not in webrat.

鹿港小镇 2024-11-08 11:26:57
integration_sign_in(wrong_user)
integration_sign_in(wrong_user)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文