【问题标题】:rspec + capybara rails 4 - rake integration testing failsrspec + capybara rails 4 - rake 集成测试失败
【发布时间】:2015-05-15 12:24:50
【问题描述】:

我正在尝试测试设计登录、注销和所有其他场景,但是我无法让一个场景过去,让我们登录失败

在我的功能中我有

scenario 'user cannot sign in if not registered' do
   login_as('user2@example.com', 'meow')
   visit overviews_path
   save_and_open_page
    expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
end

我还将登录助手设置为;

 def sign_in(email, password)
  user.confirm!
  visit new_user_session_path
  fill_in 'Email', with: email
  fill_in 'password', with: password
  click_button 'Log in'
end

但是这会产生错误;

expected to find text "Invalid email or password." in "TypeError at /overviews ======================= > no implicit conversion of Symbol into Integer spec/features/users/sign_in_spec.rb, line 14

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails ruby rspec devise capybara


    【解决方案1】:

    您将帮助方法命名为 sign_in,但在您的场景中调用的是 login_as。您应该使用一种方法或另一种方法,而不是两种方法。

    更新:好的,重新检查了documentation,您应该使用自己的帮助程序来模拟实际用户登录,或者使用 Warden 提供的login_as,在这种情况下,请确保您是将此包含在您的测试/ rspec 设置中:

    include Warden::Test::Helpers
    Warden.test_mode!
    

    附带说明,您应该在您的工厂/夹具中确认您的用户,而不是在您的辅助方法中(可能未定义)。

    【讨论】:

    • 感谢您,我最终删除了额外的帮助程序并移回了守望者 login_as,我确保我包括了守望者 Test::Helpers 但是我现在遇到了一个不同的问题失败/错误: expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email' 期望找到文本“无效的电子邮件或密码”。在“TypeError at /overviews =======================> 没有将符号隐式转换为整数
    • 您的概览控制器是什么样的?从哪一行触发“将符号隐式转换为整数”?这与登录内容不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多