[英]How do I use Rack/Test to test Sinatra redirects? The App works, but the test doesn't
[英]Rack error with capybara/sinatra test… Doesn't seem to get the Sinatra app passed on
嘗試設置capybara / rspec來測試一個簡單的sinatra應用程序,但始終出現機架錯誤。
hello.rb的
require 'sinatra'
class App < Sinatra::Base
get "/" do
"hello hello!"
end
run! if app_file == $0
end
投機/ hello_spec.rb
require File.join(File.dirname(__FILE__), '..', 'hello.rb')
require 'rspec'
require 'capybara'
require 'capybara/dsl'
require 'capybara/rspec'
set :environment, :test
describe 'The Hello App' do
include Capybara::DSL
def setup
Capybara.app = App
end
it "says hello when browsing /" do
visit '/'
page.should have_content('hello')
end
end
注意,我也嘗試過
def setup
Capybara.app = App.new
end
哪個產生了同樣的錯誤。
錯誤:
C:\Sites\misc\qrgen>bundle exec rspec
F
Failures:
1) The Hello App says hello when browsing /
Failure/Error: visit '/'
ArgumentError:
rack-test requires a rack application, but none was given
# ./spec/hello_spec.rb:18:in `block (2 levels) in <top (required)>'
Finished in 0.374 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/hello_spec.rb:17 # The Hello App says hello when browsing /
有和沒有bundle exec時運行相同的錯誤。 有任何想法嗎?
的Gemfile:
gem "sinatra"
gem "sinatra-contrib"
gem "sinatra-flash"
gem "slim"
gem "rspec"
gem "capybara"
gem "rack-test"
希望這對嘗試從Sinatra文檔中進行測試的其他人很有用。
更改
def setup
Capybara.app = App
end
至
Capybara.app = App
解決了問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.