无法加载此类文件 -- capybara/minitest
cannot load such file -- capybara/minitest
希望有人能帮我解决这个问题。我进行了搜索,但没有找到任何可行的解决方案。
我已经开始为应用程序编写测试。我的集成测试 运行 很好,但后来我决定,因为我不太受 TDD 驱动,而且我现在没有那么多时间来广泛测试我应该使用的应用程序的所有层integration
个测试 system
个测试,因为它们允许我像在浏览器中一样测试完整流程。
Rails 5.1.2
Gemfile
(尝试了不同的变体,只是水豚,然后是其他两个的组合)
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
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
application_system_test_case.rb
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
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
运行宁
时出错
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)
完整的跟踪添加了这个:
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)>'
并继续 active_support 依赖项。
我尝试过的:
将一、二和三加到 test_helper.rb
:
require "capybara/rails"
require "minitest/rails"
require "minitest/rails/capybara"
我试过使用宝石:
group :development, :test do
gem 'minitest-rails'
gem 'minitest-capybara'
gem 'capybara'
end
然后 'minitest-rails-capybara'
谢谢
文件capybara/minitest
在版本2.13.0中添加到Capybara,这是自Rails 5.1.0以来系统测试所需的最低版本Rails。升级到最新版本的 Capybara (2.14.4),应该不需要 minitest-capybara
或 minitest-rails
gems。您还需要将 'selenium-webdriver' gem 添加到您的测试组。
此外,assert_response :success
行在 Capybara 测试中无效,因为 Capybara 使用的浏览器的 HTTP 响应代码通常不可用。
希望有人能帮我解决这个问题。我进行了搜索,但没有找到任何可行的解决方案。
我已经开始为应用程序编写测试。我的集成测试 运行 很好,但后来我决定,因为我不太受 TDD 驱动,而且我现在没有那么多时间来广泛测试我应该使用的应用程序的所有层integration
个测试 system
个测试,因为它们允许我像在浏览器中一样测试完整流程。
Rails 5.1.2
Gemfile
(尝试了不同的变体,只是水豚,然后是其他两个的组合)
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
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
application_system_test_case.rb
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
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
运行宁
时出错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)
完整的跟踪添加了这个:
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)>'
并继续 active_support 依赖项。
我尝试过的:
将一、二和三加到 test_helper.rb
:
require "capybara/rails"
require "minitest/rails"
require "minitest/rails/capybara"
我试过使用宝石:
group :development, :test do
gem 'minitest-rails'
gem 'minitest-capybara'
gem 'capybara'
end
然后 'minitest-rails-capybara'
谢谢
文件capybara/minitest
在版本2.13.0中添加到Capybara,这是自Rails 5.1.0以来系统测试所需的最低版本Rails。升级到最新版本的 Capybara (2.14.4),应该不需要 minitest-capybara
或 minitest-rails
gems。您还需要将 'selenium-webdriver' gem 添加到您的测试组。
此外,assert_response :success
行在 Capybara 测试中无效,因为 Capybara 使用的浏览器的 HTTP 响应代码通常不可用。