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

m3characters
  • 2,240
  • 2
  • 14
  • 18
  • 1
    What version of Capybara are you using? – Thomas Walpole Jul 19 '17 at 22:06
  • capybara (2.6.2) @ThomasWalpole – m3characters Jul 19 '17 at 22:08
  • 1
    Rails 5.1 system tests need at least 2.13.0 (might as well use the latest (2.14.4) and then should no longer need `minitest-capybara` or `minitest-rails` gems - you will need 'selenium-webdriver' for the default setup though – Thomas Walpole Jul 19 '17 at 22:10
  • Thank you @ThomasWalpole, that solved it, just had to add chromedriver afterwars and all working. Please add it as an answer and I'll accept it. And yes, assert_response is useless. Btw, maybe you can also offer me your opinion, is there any significant reason to use selenium instead of a headless browser? I just run those 4 lines of code and it took like eternity – m3characters Jul 19 '17 at 22:38
  • 1
    Selenium is running a modern browser, neither of the headless browser drivers (capybara-webkit, poltergeist) support anything beyond ES5 today and have a few other limitations too (video, audio, etc). Because of that using selenium is a more "correct" representation of a user. You can now also run selenium with headless Chrome, which doesn't add much speed yet but hopefully will in the future. Also there is a lot of overhead in getting the one test running which will amortize when you have multiple tests. – Thomas Walpole Jul 19 '17 at 22:41
  • Thanks, I'll use that then since it will be testing some heavy JS scripts. Very much appreciated you taking the time and solving this. – m3characters Jul 19 '17 at 22:43

1 Answers1

5

The file capybara/minitest was added to Capybara in version 2.13.0, which is the minimum version Rails requires for its system tests since Rails 5.1.0. Upgrade to the latest version of Capybara (2.14.4) and there should be no need for the minitest-capybara or minitest-rails gems. You will need to also add the 'selenium-webdriver' gem to your test group.

Additionally the assert_response :success line is't valid in Capybara tests because the HTTP response code from the browser Capybara is using isn't generally available.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • thanks, I added a comment, if you care to share your opinion on using selenium or a headless one, like poltergeist/cb-webkit, I would appreciate it – m3characters Jul 19 '17 at 22:40