无法加载此类文件-capybara / minitest

m3c*_*ers 0 ruby-on-rails minitest system-testing capybara

希望有人可以帮助我。我确实进行了搜索,但没有找到任何有效的解决方案。

我已经开始为应用编写测试。我的集成测试运行正常,但后来我决定,那么多的TDD的驱动,因为我没有,因为我没有那么多时间,现在要进行广泛的测试应用程序的所有层,我应该使用的,而不是integration检验system测试,因为它们使我可以像在浏览器中一样测试整个流程。

Rails 5.1.2

Gemfile (尝试了不同的变化,只是水豚,然后结合了其他两个)

gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
Run Code Online (Sandbox Code Playgroud)

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  EMPTY_NEW_USER = {
    email: '',
    first_name: '',
    last_name: '',
    username: '',
    password: ''
  }

  EXISTING_USER = {
    email: '****',
    first_name: 'John',
    last_name: 'Doe',
    username: '',
    password: 'testingpass',
    password_confirmation: 'testingpass'
  }

  # Add more helper methods to be used by all tests here...
end
Run Code Online (Sandbox Code Playgroud)

application_system_test_case.rb

require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
Run Code Online (Sandbox Code Playgroud)

register_logins.rb

require "application_system_test_case"

class RegisterLoginsTest < ApplicationSystemTestCase

  test 'full login flow' do
    visit root_url
    assert_response :success

    find('.email_link').click


  end
end
Run Code Online (Sandbox Code Playgroud)

运行时错误

rake test:system

LoadError: cannot load such file -- capybara/minitest
/Users/mnussbaumer/code/dvouch/test/application_system_test_case.rb:3:in `<top (required)>'
/Users/mnussbaumer/code/dvouch/test/system/register_logins_test.rb:1:in `<top (required)>'
Tasks: TOP => test:system
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)

完整的跟踪将添加以下内容:

LoadError: cannot load such file -- capybara/minitest
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `require'
/Users/mnussbaumer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-5.1.2/lib/action_dispatch/system_test_case.rb:2:in `<top (required)>'
/Users/mnussbaumer/code/dvouch/test/application_system_test_case.rb:3:in `<top (required)>'
Run Code Online (Sandbox Code Playgroud)

并继续进行active_support依赖性。

我尝试过的

在其中添加一,二和三test_helper.rb

require "capybara/rails"
require "minitest/rails"
require "minitest/rails/capybara"
Run Code Online (Sandbox Code Playgroud)

我尝试了宝石:

group :development, :test do
  gem 'minitest-rails'
  gem 'minitest-capybara'
  gem 'capybara'
end
Run Code Online (Sandbox Code Playgroud)

然后用 'minitest-rails-capybara'

谢谢

Tho*_*ole 5

该文件capybara/minitest已添加到2.13.0版的Capybara中,这是Rails 5.1.0以来Rails进行系统测试所需的最低版本。升级到最新版本的水豚(2.14.4),就不需要minitest-capybaraminitest-rails宝石。您还需要将“ selenium-webdriver” gem添加到测试组。

此外,该assert_response :success行在Capybara测试中无效,因为通常不会提供来自Capybara使用的浏览器的HTTP响应代码。