108 lines
2.6 KiB
Ruby
Raw Normal View History

require 'cucumber/rails'
2014-07-24 00:16:33 -06:00
require 'capybara/poltergeist'
2015-09-01 20:50:45 -07:00
require 'mocha/mini_test'
2017-04-09 11:37:16 -07:00
require 'fileutils'
require 'marmara'
ActionController::Base.allow_rescue = false
2017-04-09 11:37:16 -07:00
DatabaseCleaner.strategy = :truncation, { except: %w[cities city_cache] }
Capybara.register_driver :bb_poltergeist do |app|
if ENV['CSS_TEST']
Marmara.options = {
ignore: [/paypal(?:objects)?/, 'assets.css'],
2017-04-09 11:37:16 -07:00
rewrite: {
from: /^.*\/(.*?)\/.*?\.css$/,
to: '\1.css'
},
minimum: {
declarations: 30
}
}
Marmara.start_recording
end
opts = {
2017-04-11 21:42:29 -07:00
timeout: 10,
2017-04-09 11:37:16 -07:00
window_size: [1200, 800]
}
Capybara::Poltergeist::Driver.new(app, opts)
end
2015-08-18 22:18:29 -07:00
Before('@javascript') do
2017-04-09 11:37:16 -07:00
ActiveRecord::Base.shared_connection = nil
ActiveRecord::Base.descendants.each do |model|
model.shared_connection = nil
end
2015-08-18 22:18:29 -07:00
end
2014-07-24 00:16:33 -06:00
Before do
2017-04-09 11:37:16 -07:00
TestState.reset!
safari5 = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
2017-04-12 00:43:36 +00:00
safari9 = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/9.3.2 Safari/537.75.14"
2017-04-09 11:37:16 -07:00
chrome55 = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
2017-04-13 20:43:13 -07:00
ActionDispatch::Request.any_instance.stubs(:user_agent).returns(safari5)
2017-04-09 11:37:16 -07:00
LinguaFranca.test_driver = page.driver
host = "http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}"
LinguaFranca.host = host
Mail::TestMailer.deliveries.clear
2014-07-24 00:16:33 -06:00
end
2015-08-18 22:18:29 -07:00
After do |scenario|
2017-04-09 11:37:16 -07:00
log_result scenario
2017-04-11 21:42:29 -07:00
if LinguaFranca.recording?
sleep 1
LinguaFranca.screenshot_mail
end
2017-04-09 11:37:16 -07:00
if scenario.failed?
if @exception
puts @exception.to_s
puts @exception.backtrace.join("\n")
end
end
2015-08-18 22:18:29 -07:00
end
After do
2017-04-09 11:37:16 -07:00
DatabaseCleaner.clean
2015-08-18 22:18:29 -07:00
end
2014-07-24 00:16:33 -06:00
2017-06-11 15:27:18 -07:00
def step_wait_time(keyword)
# give additional wait time to Given and When steps
if keyword == 'And' || keyword == 'But'
keyword = @_last_keyword
end
@_last_keyword = keyword
case keyword
when 'Given'
return 1
when 'When'
return 3
end
return 0.5
end
AfterStep do |scenario, step|
2017-04-09 11:37:16 -07:00
# capture used selectors to generate css coverage
2017-06-11 15:27:18 -07:00
Marmara.record(step.source.last.keyword) if Marmara.recording?
2014-07-24 00:16:33 -06:00
2017-04-09 11:37:16 -07:00
# take some extra time between steps if we're recording
2017-06-11 15:27:18 -07:00
keyword = step.source.last.keyword.strip
sleep(step_wait_time(keyword)) if LinguaFranca.recording?
2014-07-24 00:16:33 -06:00
end
2015-08-18 22:18:29 -07:00
Cucumber::Rails::Database.javascript_strategy = :transaction
Capybara.default_driver = :bb_poltergeist
Capybara.javascript_driver = :bb_poltergeist
2017-04-09 11:37:16 -07:00
Geocoder.configure(timeout: 60)
2017-04-09 11:37:16 -07:00
at_exit do
Marmara.stop_recording if Marmara.recording?
2014-07-24 00:16:33 -06:00
end