2011-02-18 22:53:06 -05:00
|
|
|
require 'rspec'
|
2011-10-06 11:07:20 -04:00
|
|
|
require 'rbconfig'
|
2012-07-08 16:38:19 -04:00
|
|
|
require 'capybara'
|
2011-02-18 22:53:06 -05:00
|
|
|
|
|
|
|
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
|
|
|
|
|
|
|
$LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
|
|
|
|
|
|
|
|
Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
|
|
|
|
|
2012-07-08 15:17:08 -04:00
|
|
|
require 'capybara/webkit'
|
2016-04-05 17:18:14 -04:00
|
|
|
$webkit_server = Capybara::Webkit::Server.new
|
|
|
|
$webkit_connection = Capybara::Webkit::Connection.new(server: $webkit_server)
|
2014-06-18 18:00:34 -04:00
|
|
|
$webkit_browser = Capybara::Webkit::Browser.new($webkit_connection)
|
2011-03-11 11:19:59 -05:00
|
|
|
|
2012-07-08 19:09:40 -04:00
|
|
|
if ENV['DEBUG']
|
|
|
|
$webkit_browser.enable_logging
|
|
|
|
end
|
|
|
|
|
2013-02-17 11:19:38 -05:00
|
|
|
require 'capybara/spec/spec_helper'
|
2012-07-08 16:38:19 -04:00
|
|
|
|
2011-04-14 10:16:56 -04:00
|
|
|
Capybara.register_driver :reusable_webkit do |app|
|
2012-07-08 15:17:08 -04:00
|
|
|
Capybara::Webkit::Driver.new(app, :browser => $webkit_browser)
|
2011-04-14 10:16:56 -04:00
|
|
|
end
|
2012-01-27 10:26:05 -05:00
|
|
|
|
2015-03-20 16:07:34 -04:00
|
|
|
def has_internet?
|
|
|
|
require 'resolv'
|
|
|
|
dns_resolver = Resolv::DNS.new
|
|
|
|
begin
|
|
|
|
dns_resolver.getaddress("example.com")
|
|
|
|
true
|
2015-04-11 21:08:28 -04:00
|
|
|
rescue Resolv::ResolvError
|
2015-03-20 16:07:34 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-30 22:12:11 -05:00
|
|
|
RSpec.configure do |c|
|
2014-06-18 18:00:34 -04:00
|
|
|
Capybara::SpecHelper.configure(c)
|
|
|
|
|
2012-11-30 22:12:11 -05:00
|
|
|
c.filter_run_excluding :skip_on_windows => !(RbConfig::CONFIG['host_os'] =~ /mingw32/).nil?
|
2014-01-28 19:17:16 -05:00
|
|
|
c.filter_run_excluding :skip_on_jruby => !defined?(::JRUBY_VERSION).nil?
|
2014-07-08 23:55:06 -04:00
|
|
|
c.filter_run_excluding :selenium_compatibility => (Capybara::VERSION =~ /^2\.4\./).nil?
|
2015-03-20 16:07:34 -04:00
|
|
|
c.filter_run_excluding :skip_if_offline => !has_internet?
|
2014-06-18 18:00:34 -04:00
|
|
|
|
2015-04-11 21:08:28 -04:00
|
|
|
#Check for QT version is 4 to skip QT5 required specs
|
|
|
|
#This should be removed once support for QT4 is dropped
|
|
|
|
require 'capybara_webkit_builder'
|
|
|
|
c.filter_run_excluding :skip_on_qt4 => !(%x(#{CapybaraWebkitBuilder.qmake_bin} -v).match(/Using Qt version 4/)).nil?
|
|
|
|
|
2017-02-03 14:20:27 -05:00
|
|
|
# We can't support outerWidth and outerHeight without a visible window. Only affects Capybara < 2.12.0
|
2014-06-18 18:00:34 -04:00
|
|
|
# We focus the next window instead of failing when closing windows.
|
2017-02-03 14:20:27 -05:00
|
|
|
# Accessing unattached nodes is allowed when reload is disabled - Legacy behavior
|
|
|
|
# Node#send_keys does not support modifiers and only supports a subset of special keys
|
2015-08-28 07:52:16 -04:00
|
|
|
c.filter_run_excluding :full_description => lambda { |description, metadata|
|
2017-02-06 20:29:11 -05:00
|
|
|
(description =~ /Capybara::Session webkit node #reload without automatic reload should not automatically reload/ ||
|
|
|
|
if Gem::Version.new(Capybara::VERSION) < Gem::Version.new("2.12.0")
|
|
|
|
description =~ /Capybara::Session webkit Capybara::Window\s*#(size|resize_to|maximize|close.*no_such_window_error)/ ||
|
|
|
|
description =~ /Capybara::Session webkit node\s*#set should allow me to change the contents of a contenteditable elements child/
|
|
|
|
else
|
|
|
|
description =~ /Capybara::Session webkit Capybara::Window\s*#close.*no_such_window_error/
|
|
|
|
end
|
2016-01-28 11:52:34 -05:00
|
|
|
)
|
2015-08-28 07:52:16 -04:00
|
|
|
}
|
2012-11-30 22:12:11 -05:00
|
|
|
end
|
|
|
|
|
2012-01-27 10:26:05 -05:00
|
|
|
def with_env_vars(vars)
|
2012-02-15 10:49:22 -05:00
|
|
|
old_env_variables = {}
|
2012-01-27 10:26:05 -05:00
|
|
|
vars.each do |key, value|
|
|
|
|
old_env_variables[key] = ENV[key]
|
|
|
|
ENV[key] = value
|
|
|
|
end
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
old_env_variables.each do |key, value|
|
|
|
|
ENV[key] = value
|
|
|
|
end
|
|
|
|
end
|