gpt4 book ai didi

ruby - Sinatra rspec capybara : "rack test requires a rack application"

转载 作者:太空宇宙 更新时间:2023-11-03 16:19:59 26 4
gpt4 key购买 nike

当运行 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

任何方向将不胜感激。

谢谢

俄罗斯人

最佳答案

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

除其他外,它建议将以下内容添加到您的 spec_helper.rb:

module RSpecMixin
include Rack::Test::Methods
def app() Sinatra::Application end
end

RSpec.configure do |config|
config.include RSpecMixin
end

关于ruby - Sinatra rspec capybara : "rack test requires a rack application",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com