Sinatra rspec capybara:“机架测试需要机架应用程序”

时间:2016-02-03 10:37:24

标签: ruby rspec sinatra capybara

运行rspec以使用Sinatra Base测试功能测试时,我们收到以下错误。

这就是我们的功能测试的外观

require 'capybara/rspec'

    feature 'Enter names' do
      scenario 'submitting names' do
      visit('/')
      fill_in :player_1_name, with: 'Dave'
      fill_in :player_2_name, with: 'Mittens'
      click_button 'Submit'
      expect(page).to have_content 'Dave vs. Mittens'
      end
      end

这是我们的Gemfile:

source 'https://rubygems.org'
 gem 'sinatra'
 gem 'rspec-sinatra'
 gem 'capybara'

错误:

 1.1) Failure/Error: visit "/"
      ArgumentError:
        rack-test requires a rack application, but none was given
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `call'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:227:in `visit'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
      # ./spec/feature/feature_spec.rb:5:in `block (2 levels) in <top (required)>'

 1.2) Failure/Error: Unable to find matching line from backtrace
      ArgumentError:
        rack-test requires a rack application, but none was given
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rack_test/driver.rb:16:in `initialize'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `new'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:372:in `block in <top (required)>'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `call'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:79:in `driver'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/session.rb:103:in `reset!'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `block in reset_sessions!'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `each'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara.rb:257:in `reset_sessions!'
      # /Users/Russell/.rvm/gems/ruby-2.2.3/gems/capybara-2.4.4/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'

我们已经尝试在功能测试中要求spec_helper文件,并且还要求我们在功能测试中使用app.rb,我们得到一个不同的错误,说它无法加载sinatra-base

Here is our spec_helper 

ENV['RACK_ENV'] = 'test'

require File.join(File.dirname(__FILE__), '..', 'app.rb')

require 'capybara'
require 'capybara/rspec'
require 'rspec'

Capybara.app = Battle

RSpec.configure do |config|
config.include Capybara::DSL

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


end

任何方向都会受到大力赞赏。

由于

拉​​斯

1 个答案:

答案 0 :(得分:1)

看看这里: http://recipes.sinatrarb.com/p/testing/rspec

除其他外,它建议将以下内容添加到F1 = 2 * (AveragePrecision * AverageRecall) / (AveragePrecision + AverageRecall)

spec_helper.rb