我沒有得到水豚與我的模塊化sinatra應用程序一起工作。我創建了一個小測試應用程序,並具有相同的問題。我總是得到一個504超時錯誤,我認爲這個應用並不是真的由Capybara加載的,無論accept_helper中的線Capybara.app = Testapp
如何。在SInatra應用程序中集成Capybara與rspec結果始終在504測試
瀏覽器Firefox在測試運行時打開,但不會轉到任何URL並始終顯示空白網站。
當我只使用rspec進行同樣的測試時(第二個)。
我做錯了什麼?
我的設置:
OS: Win 7 Professional 64-bit
Ruby version: ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32]
Firefox version: 40.0.3
gem versions
- sinatra (1.4.6)
- rspec (3.3.0)
- capybara (2.7.1)
- selenium-webdriver (2.53.4)
- thin (1.5.1)
- rack (1.6.4)
- rack-test (0.6.3)
應用結構:
test_sinatra_capybara
|
|- testapp.rb
|- spec
| |- spec_helper.rb
| |- acceptance_helper.rb
| |- testapp_spec.rb
|- views
| |- index.slim
testapp.rb
require 'sinatra'
require 'sinatra/base'
require 'slim'
class Testapp < Sinatra::Base
get '/' do
slim :index
end
end
index.slim
#test-id
| Willkommen
spec_helper.rb
require 'rspec'
require 'rack/test'
require_relative '../testapp'
Testapp.environment = :test
module RSpecMixin
include Rack::Test::Methods
def app() Testapp end
end
RSpec.configure do |config|
config.include RSpecMixin
# Use color in STDOUT
config.color = true
# Use the specified formatter
config.formatter = :documentation
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
acceptance_helper.rb
require File.dirname(__FILE__) + '/spec_helper'
require 'capybara'
require 'capybara/rspec'
Capybara.default_driver = :selenium
Capybara.app = Testapp
RSpec.configure do |config|
config.include Capybara::DSL
config.include Capybara::RSpecMatchers
end
testapp_spec.rb
require File.dirname(__FILE__) + '/acceptance_helper'
describe 'URLs that require login' do
it "start page capybara" do
# I tried both
visit '/'
# visit 'http:localhost:4567'
page.should have_content("Willkommen")
end
it "start page rspec" do
get "/"
expect(last_response.body).to include("Willkommen")
end
end
所以,正如我所說的,最後的測試工作:
Finished in 12.91 seconds (files took 2.54 seconds to load)
2 examples, 1 failure
Failed examples:
rspec ./spec/testapp_spec.rb:4 # URLs that require login start page capybara
錯誤在第一次測試:
Selenium::WebDriver::Error::WebDriverError:
unexpected response, code=504, content-type="text/html"
如果以後'visit'什麼網址暫停測試瀏覽器試圖連接到? –
您的代理權利。我忘了顯示信息。但是Localhost(127.0.0.1)不應該受到影響。我手動禁用它,仍然無法正常工作。 瀏覽器的窗口始終是空白的,所以水豚可以打開瀏覽器,但然後它沒有去我的意見任何網址。 我目前的FF版本是40.0.3,也許是我最後一次嘗試這個的原因,因爲在我看來它不是老的。硒寶石是2.53.4 Thx爲Capybara.server_ *配置東西我不知道,但它仍然失敗。 – Quackerjack