我开始为应用编写测试。我的集成测试运行良好,但后来我决定,因为我没有那么多的TDD驱动,因为我现在没有那么多时间来广泛测试我应该使用的所有应用层而不是{{1测试integration
测试,因为它们允许我像在浏览器中一样测试完整的流程。
system
Rails 5.1.2
(尝试了不同的变化,只是水豚,然后是其他两个的组合)
Gemfile
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'capybara'
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
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
end
运行时出现 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)
继续使用active_support依赖项。
我尝试过:
将一,二和三添加到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)>'
:
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
由于
答案 0 :(得分:5)
文件capybara/minitest
已在版本2.13.0中添加到Capybara,这是Rails自Rails 5.1.0以来进行系统测试所需的最低版本。升级到最新版本的Capybara(2.14.4),不需要minitest-capybara
或minitest-rails
宝石。您还需要添加&#39; selenium-webdriver&#39;宝石给你的测试组。
此外,assert_response :success
行在Capybara测试中无效,因为来自浏览器Capybara的HTTP响应代码通常不可用。