2015-11-19 101 views
0

我正在寫入功能測試:ruby 2.1.4,rails 4.1.12,rspec (2.14.1),capybara (2.4.1)poltergeist (1.5.1)爲什麼在CodeShip上使用JavaScript進行Rspec測試失敗?

目前我有這樣一個特點:

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上 - 這種情況總是失敗。

Capybara::Poltergeist::StatusFailError: 
Request to 'http://127.0.0.1:3000/' failed to reach server, check DNS and/or server status 

但爲什麼: 爲什麼...

CodeShip日誌說,我找不到理由嗎?本地所有測試都是綠色的。

P.S.我試圖在行visit root_path之前添加sleep 5,但它沒有幫助。

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

嘗試把sleep(5)visit root_path並再次檢查,如果測試失敗

+0

它並不能幫助:(我嘗試添加'把page.current_url'在'訪問root_path'後 - 它返回我''頁面:空白「'而不是'」/ sign_in「' – bmalets

+0

看起來像不打開'root_path'頁面,但是爲什麼?O_o – bmalets

+0

AND capybara應該自動等待,shouldn 't it? – bmalets