Le mie specifiche di funzionalità molto semplici stanno passando bene localmente ma non funzionano su CircleCI e Codeship. I test che non riescono:Le specifiche delle caratteristiche falliscono solo sui servizi di integrazione continua CircleCI o Codeship
require 'spec_helper'
describe 'Authentication' do
describe "sign in" do
it "is the landing page for non-authenticated users" do
user = create(:user)
visit root_path
expect(page).to have_content 'LOG IN' # On sign-in page
fill_in 'Email', with: user.email
fill_in "Password", with: user.password
click_button 'Sign in'
expect(current_path).to eq user_path(user)
end
end
describe 'registration' do
it "allows new users to register" do
visit root_path
click_link 'Sign up'
fill_in 'Email', with: '[email protected]'
fill_in 'Password', with: 'password'
fill_in 'Password confirmation', with: 'password'
fill_in 'First name', with: 'John'
fill_in 'Last name', with: 'Doe'
click_button "Sign up"
expect(current_path).to include '/users/'
expect(page).to have_content "Welcome! You have signed up successfully."
end
end
end
I test sia falliscono sulle prime righe in cui definire le aspettative delle pagine (rispettivamente expect(page).to have_content "LOG IN"
e click_link "Sign up"
,), con errori che suggeriscono la pagina HTML è completamente vuota:
expected to find text "LOG IN" in ""
Ho salvato screenshot su CircleCI e in effetti mostrano una pagina completamente vuota.
Ecco dove diventa interessante. Ho provato il debug del problema da running/watching the specs on Circle using a VNC. Quando ho a) impostato driver: :selenium
per le prove, b) aggiungere un sleep 1
o due per le prove prima di testare le aspettative di pagina, e c) eseguire manualmente il test dopo sshing loro server con il VNC, che posso vedere i test eseguiti in Selenium (aprono un browser nel VNC) e passano perfettamente.
Al di fuori del VNC, tuttavia, i test hanno esito negativo in modo coerente in entrambi i server CI. Con o senza tonnellate di sleep
se driver: :selenium
. Qualche idea che cosa potrebbe causare questa discrepanza tra i normali server CircleCI/Codeship e il loro VCN/il mio ambiente di test locale? Mi sono messo in contatto con la gente di CircleCI, ma per un momento sono perplessi.
Se del caso, sto correndo di Ruby 2.2.0, Rails 4.2, Capybara 2.4.4, Capybara-Webkit 1.4.1, e selenio-WebDriver 2.44.0
Alcuni file potenzialmente rilevanti :
spec_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rspec/rails"
require "shoulda/matchers"
require "webmock/rspec"
require 'vcr'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |file| require file }
module Features
include Warden::Test::Helpers
Warden.test_mode!
def sign_in(user)
login_as(user, scope: :user)
end
end
module Controllers
# Pre-parse controller responses for easy access
def response_body
body = JSON.parse(response.body)
body.is_a?(Hash) ? body.to_sh : body.map(&:to_sh)
end
end
module Mock
def disable_webmock(&block)
WebMock.disable!
yield
WebMock.enable!
end
end
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
# Save a screenshot to CircleCI when a feature test fails
config.after(:each, :type => :feature) do |example|
if example.exception
artifact = save_page
puts "\"#{example.description}\" failed. Page saved to #{artifact}"
end
end
config.include Features, type: :feature
config.include Controllers, type: :controller
config.include Mock
config.include Formulaic::Dsl, type: :feature
config.infer_spec_type_from_file_location!
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.use_transactional_fixtures = false
end
RSpec::Matchers.define :hash_eq do |expected|
match do |actual|
actual.recursive_symbolize_keys == expected.recursive_symbolize_keys
end
end
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
c.allow_http_connections_when_no_cassette = true
c.configure_rspec_metadata!
c.ignore_hosts '127.0.0.1', 'localhost:3000'
end
ActiveRecord::Migration.maintain_test_schema!
Capybara.javascript_driver = :webkit
if ENV['CIRCLE_ARTIFACTS']
Capybara.save_and_open_page_path = ENV['CIRCLE_ARTIFACTS']
end
WebMock.disable_net_connect!(allow_localhost: true)
database_cleaner.rb
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
Questo potrebbe essere un problema di configurazione CircleCI. Puoi condividere anche il tuo file cicle.yml? –
Stai usando un servizio headless o Saas? La maggior parte di questi programmi CI sono privi di testa e non possono eseguire qualcosa come il selenio senza un vero lavoro. – TIMBERings
Se usi il selenio, puoi provare con Firefox 28.0. – juanitofatas