为什么在CodeShip上使用javascript进行Rspec测试失败?

时间:2015-11-19 23:30:21

标签: rspec phantomjs capybara poltergeist codeship

我正在撰写功能测试:ruby 2.1.4rails 4.1.12rspec (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

1 个答案:

答案 0 :(得分:0)

尝试将sleep(5)放在visit root_path后再次检查测试是否失败