我正在撰写功能测试: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
但为什么呢?当地所有测试都是绿色的。
P.S。我尝试在行sleep 5
之前添加visit root_path
,但没有帮助。
P.S.S。也许这部分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
答案 0 :(得分:0)
尝试将sleep(5)
放在visit root_path
后再次检查测试是否失败