0

hope somebody can help me with this. I did search but haven't found any working solution.

I've started writing test for an app. My integration tests run fine, but then I decided that since I'm not that much of TDD driven and since I don't have that much time right now to extensively test all layers of the app that I should use instead of integration tests system tests, because they allow me to test the full flow as if in a browser.

Rails 5.1.2

Gemfile (tried different variations, just capybara, then with combinations of both the other two)

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

error when running

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)

The full trace adds this:

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)>'

and goes on on active_support dependencies.

What I have tried:

Adding one, two and three to test_helper.rb:

require "capybara/rails"
require "minitest/rails"
require "minitest/rails/capybara"

I tried with gems:

group :development, :test do
  gem 'minitest-rails'
  gem 'minitest-capybara'
  gem 'capybara'
end

then with 'minitest-rails-capybara'

Thanks

4

1 回答 1

5

该文件capybara/minitest在 2.13.0 版本中添加到 Capybara,这是自 Rails 5.1.0 以来 Rails 系统测试所需的最低版本。升级到最新版本的 Capybara (2.14.4),应该不需要minitest-capybaraor minitest-railsgems。您还需要将“selenium-webdriver”gem 添加到您的测试组。

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

于 2017-07-19T22:36:23.530 回答