使用rails、capybara、rspec(和spring)运行特性规范时,会出现以下错误:

> rspec spec/features/home_page_spec.rb

错误:
ArgumentError:
       rack-test requires a rack application, but none was given
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./spec/features/home_page_spec.rb:22:in `block (2 levels) in <top (required)>'

示例测试错误:
Randomized with seed 4806

visitor

An error occurred in an after hook
    ArgumentError: rack-test requires a rack application, but none was given
    occurred at /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'

  visits homepage (FAILED - 1)

所以,如果有帮助的话,这是我的gemfile:
group :development, :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'faker'
  gem 'capybara'
  gem 'spring',      '1.1.3'
end

spec_helper,如果有帮助:
require 'devise'
require 'capybara/rspec'

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.include Capybara::DSL

  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  if config.files_to_run.one?
    config.default_formatter = 'doc'
  end
  config.profile_examples = 10
  config.order = :random

  Kernel.srand config.seed
end

还有我的Rails助手:
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'

# Add additional requires below this line. Rails is not loaded until this point!
require 'capybara/rails'

ActiveRecord::Migration.check_pending!

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.use_transactional_fixtures = true
  config.include Devise::TestHelpers, :type => :controller


  config.infer_spec_type_from_file_location!
end

UPD主页_spec.rb:
require 'spec_helper'

feature "visitor" do

  # describe 'on desktop' do

    scenario 'visits homepage' do

      visit '/'

      expect(page).to have_content('Drivers')

    end

    scenario 'visits employer page' do
      visit '/hire'
      expect(page).to have_content('DriverHunt')
    end

    scenario 'visits contact page' do

      visit '/contact'

      expect(page).to have_content('DriverHunt')

    end

    scenario 'visits terms' do

      visit '/terms'

      expect(page).to have_content('DriverHunt')

    end

    scenario 'visits privacy' do

      visit '/privacy'

      expect(page).to have_content('DriverHunt')

    end

  # end


  # describe 'on mobile' do

  #   scenario 'visits homepage' do
  #     visit '/?mobile=1'
  #     expect(page).to have_content('Drivers')
  #   end

  #   scenario 'visits employer page' do
  #     visit '/hire?mobile=1'
  #     expect(page).to have_content('DriverHunt')
  #   end

  #   scenario 'visits contact page' do

  #     visit '/contact?mobile=1'

  #     expect(page).to have_content('DriverHunt')

  #   end

  #   scenario 'visits terms' do

  #     visit '/terms?mobile=1'

  #     expect(page).to have_content('DriverHunt')

  #   end

  #   scenario 'visits privacy' do

  #     visit '/privacy?mobile=1'

  #     expect(page).to have_content('DriverHunt')

  #   end

  # end


end

# #   before :each do
# #     User.make(:email => '[email protected]', :password => 'password')
# #   end

#   # it "signs me in" do
# #     visit '/sessions/new'
# #     within("#session") do
# #       fill_in 'Email', :with => '[email protected]'
# #       fill_in 'Password', :with => 'password'
# #     end
# #     click_button 'Sign in'
# #     expect(page).to have_content 'Success'
# #   end

#   it "finds the homepage" do
#     visit '/'
#     expect(page).to have_content 'Driverdasdasd'
#   end

最佳答案

尝试:

cd spec
rspec features/home_page_spec.rb

关于ruby-on-rails - 机架测试需要机架应用程序,但是没有给出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29822303/

10-13 02:18