我正在使用:ruby 2.1.4
、rails 4.1.12
、rspec (2.14.1)
和capybara (2.4.1)
编写功能测试poltergeist (1.5.1)
。
目前我有这样的功能:
require 'spec_helper'
feature 'user is able to import videos from YouTube Channel', js: true do
before do
@user = FactoryGirl.create :user
end
scenario 'from a simple correct YouTube video link' do
VCR.use_cassette('video_sources/youtube_add_single_video') do
visit root_path
fill_in 'user_email', with: @user.email
fill_in 'user_password', with: @user.password
click_button 'Log in'
visit youtube_import_path
expect(page).to have_css("input#query")
expect(page).to have_css("a#continue-button")
fill_in "query", with: "https://www.youtube.com/watch?v=xZY43QSx3Fk"
page.find('#continue-button').trigger('click')
# clicking on '#continue-button' call youtube API
# receive a video data and store it into DB
expect(page).to have_content("Congrats! Your import is complete")
end
end
end
本地一切正常,所有测试都是绿色的。但在 CodeShip 上 - 这种情况总是失败。而且我找不到原因...
CodeShip 日志说:
Capybara::Poltergeist::StatusFailError:
Request to 'http://127.0.0.1:3000/' failed to reach server, check DNS and/or server status
但为什么?本地所有测试都是绿色的。
PS我尝试sleep 5
在行前添加visit root_path
,但没有帮助。
PSS 也许这部分会spec_helper.rb
有所帮助:
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
Capybara.reset_sessions!
end
config.before(:each) do
DatabaseCleaner[:mongoid].start
end
config.after(:each) do
DatabaseCleaner[:mongoid].clean
end
config.after(:suite) do
Rails.cache.clear
end