【问题标题】:RSpec test case failing after adding Recaptcha添加 Recaptcha 后 RSpec 测试用例失败
【发布时间】:2017-12-16 01:46:02
【问题描述】:

我添加了一个 gem recaptcha 并在我的注册和登录页面上实现了它。 但是我的测试用例很少失败。其中一个测试用例是:

require 'rails_helper'

feature 'User sessions', js: true do
  let(:organisation) {
    FactoryGirl.create(:organisation, email_domain: 'example.com')
  }

  let!(:user) {
    FactoryGirl.create(:user,
      email: 'mrbig@example.com',
      password: 'password',
      organisation: organisation)
  }

  scenario 'user signs in and out' do
    visit new_user_session_path

    expect(page).to have_content 'Log in'

    fill_in 'Email', with: 'mrbig@example.com'
    fill_in 'Password', with: 'WRONG'
    click_on 'Log in'

    expect(page).to have_content 'Invalid Email or password.'

    fill_in 'Email', with: 'mrbig@example.com'
    fill_in 'Password', with: 'password'
    click_on 'Log in'

    find('.MenuContent-logout').click

    expect(page).to have_text 'Log in'
  end
end

我已将Recaptcha.configuration.skip_verify_env.push("test") 添加到我的config/initializers/recaptcha.rb 文件中,但在我的构建中仍然失败。

我还补充了:

scenario 'user signs up' do
Users::RegistrationsController.any_instance.stub(:check_captcha).and_return(true)
# Begin signup
visit new_user_registration_path

但在这两种情况下,我都会遇到同样的错误:

【问题讨论】:

  • save_and_open_page 将向您展示页面的外观,对调试很有用

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


【解决方案1】:

似乎这是我的构建环境中的配置问题。我忘记将来自 google 服务的私钥和公钥添加到我的环境变量中。

希望这对某人有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-28
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多