2017-11-13 16:46:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-22 20:22:03 +00:00
|
|
|
POLTERGEIST_ROOT = File.expand_path('..', __dir__)
|
2011-10-31 23:04:02 +00:00
|
|
|
$:.unshift(POLTERGEIST_ROOT + '/lib')
|
2011-10-27 22:34:14 +00:00
|
|
|
|
|
|
|
require 'bundler/setup'
|
|
|
|
|
|
|
|
require 'rspec'
|
2012-12-04 14:11:27 +00:00
|
|
|
require 'capybara/spec/spec_helper'
|
2011-10-27 22:34:14 +00:00
|
|
|
require 'capybara/poltergeist'
|
|
|
|
|
|
|
|
require 'support/test_app'
|
2011-10-30 18:22:44 +00:00
|
|
|
require 'support/spec_logger'
|
2011-10-27 22:34:14 +00:00
|
|
|
|
2011-10-30 18:22:44 +00:00
|
|
|
Capybara.register_driver :poltergeist do |app|
|
2014-09-03 14:59:40 +00:00
|
|
|
debug = !ENV['DEBUG'].nil?
|
2015-09-24 22:17:08 +00:00
|
|
|
options = {
|
|
|
|
logger: TestSessions.logger,
|
|
|
|
inspector: debug,
|
|
|
|
debug: debug
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:48:18 +00:00
|
|
|
options[:phantomjs] = ENV['PHANTOMJS'] if ENV['TRAVIS'] && ENV['PHANTOMJS']
|
2015-09-24 22:17:08 +00:00
|
|
|
|
2012-02-25 12:47:18 +00:00
|
|
|
Capybara::Poltergeist::Driver.new(
|
2015-09-24 22:17:08 +00:00
|
|
|
app, options
|
2012-02-25 12:47:18 +00:00
|
|
|
)
|
2011-10-27 22:34:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module TestSessions
|
2012-02-29 13:49:17 +00:00
|
|
|
def self.logger
|
|
|
|
@logger ||= SpecLogger.new
|
|
|
|
end
|
|
|
|
|
2011-10-27 22:34:14 +00:00
|
|
|
Poltergeist = Capybara::Session.new(:poltergeist, TestApp)
|
|
|
|
end
|
2011-10-30 18:22:44 +00:00
|
|
|
|
2015-09-24 03:11:37 +00:00
|
|
|
module Poltergeist
|
|
|
|
module SpecHelper
|
|
|
|
class << self
|
|
|
|
def set_capybara_wait_time(t)
|
|
|
|
Capybara.default_max_wait_time = t
|
2018-05-22 20:22:03 +00:00
|
|
|
rescue StandardError
|
2015-09-24 03:11:37 +00:00
|
|
|
Capybara.default_wait_time = t
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-10-02 00:25:12 +00:00
|
|
|
RSpec::Expectations.configuration.warn_about_potential_false_positives = false if ENV['TRAVIS']
|
|
|
|
|
2011-10-30 18:22:44 +00:00
|
|
|
RSpec.configure do |config|
|
|
|
|
config.before do
|
2012-02-29 13:49:17 +00:00
|
|
|
TestSessions.logger.reset
|
2011-10-30 18:22:44 +00:00
|
|
|
end
|
|
|
|
|
2015-10-02 00:25:12 +00:00
|
|
|
config.after do |example|
|
2011-10-30 18:22:44 +00:00
|
|
|
if ENV['DEBUG']
|
2012-02-29 13:49:17 +00:00
|
|
|
puts TestSessions.logger.messages
|
2011-10-30 18:22:44 +00:00
|
|
|
elsif ENV['TRAVIS'] && example.exception
|
2017-11-02 19:29:10 +00:00
|
|
|
example.exception.message << "\n\nDebug info:\n" + TestSessions.logger.messages.join("\n") unless example.exception.message.frozen?
|
2011-10-30 18:22:44 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-04 14:11:27 +00:00
|
|
|
|
|
|
|
Capybara::SpecHelper.configure(config)
|
|
|
|
|
2018-05-22 20:22:03 +00:00
|
|
|
config.filter_run_excluding full_description: lambda { |description, _metadata|
|
2018-05-01 01:34:50 +00:00
|
|
|
[
|
|
|
|
# test is marked pending in Capybara but Poltergeist passes - disable here - have our own test in driver spec
|
|
|
|
/Capybara::Session Poltergeist node #set should allow me to change the contents of a contenteditable elements child/,
|
|
|
|
# should not pass because PhantomJS doesn't support datalist
|
|
|
|
/Capybara::Session Poltergeist #select input with datalist/
|
|
|
|
].any? { |desc| description =~ desc }
|
2016-06-27 22:21:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 14:11:27 +00:00
|
|
|
config.before(:each) do
|
2015-09-24 03:11:37 +00:00
|
|
|
Poltergeist::SpecHelper.set_capybara_wait_time(0)
|
2012-12-04 14:11:27 +00:00
|
|
|
end
|
|
|
|
|
2018-05-22 20:22:03 +00:00
|
|
|
%i[js modals windows].each do |cond|
|
|
|
|
config.before(:each, requires: cond) do
|
2015-09-25 18:50:05 +00:00
|
|
|
Poltergeist::SpecHelper.set_capybara_wait_time(1)
|
|
|
|
end
|
2012-12-04 14:11:27 +00:00
|
|
|
end
|
2011-10-30 18:22:44 +00:00
|
|
|
end
|
2016-06-20 23:04:10 +00:00
|
|
|
|
|
|
|
def phantom_version_is?(ver_spec, driver)
|
|
|
|
Cliver.detect(driver.options[:phantomjs] || Capybara::Poltergeist::Client::PHANTOMJS_NAME, ver_spec)
|
|
|
|
end
|