简体   繁体   中英

Rack test error while using Capybara with Rails TestCase

I've included Capybara in my integration tests. I've set up my test_helper file according to the documentation.

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

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

  # Add more helper methods to be used by all tests here...
  VCR.configure do |c|
    c.hook_into :webmock
    c.cassette_library_dir = 'vcr_cassettes'
    c.default_cassette_options = { :record => :once }
  end
end

class ActionDispatch::IntegrationTest
  # Make the Capybara DSL available in all integration tests
  include Capybara::DSL

  # Reset sessions and driver between tests
  # Use super wherever this method is redefined in your individual test classes
  def teardown
    Capybara.reset_sessions!
    Capybara.use_default_driver
  end
end

To test my integration test using Capybara, I set up a method in my portfolio_flow_test file (also require test_helper.rb)

test "signed in user can visit portfolio index page" do
  @user = users(:nicholas)
  sign_in @user
  visit portfolios_path
  assert_select "h1", "Portfolios"
end

I get this error on all my tests

ArgumentError: rack-test requires a rack application, but none was given

Capybara's default driver is rack test so I'm unclear as to why it's failing when I'm running the tests.

You haven't required 'capybara/rails' which sets up Capybara.app for your rails app. It's documented in the Capybara README - https://github.com/teamcapybara/capybara#setup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM