1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/config.rb

87 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-01-08 15:23:54 -05:00
require 'forwardable'
require 'capybara/session/config'
module Capybara
class Config
extend Forwardable
2018-01-08 15:23:54 -05:00
OPTIONS = %i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver].freeze
attr_accessor :app
attr_reader :reuse_server, :threadsafe
attr_reader :session_options
attr_writer :default_driver, :javascript_driver
SessionConfig::OPTIONS.each do |method|
def_delegators :session_options, method, "#{method}="
end
def initialize
@session_options = Capybara::SessionConfig.new
end
2018-01-09 17:05:50 -05:00
attr_writer :reuse_server
def threadsafe=(bool)
warn "Capybara.threadsafe == true is a BETA feature and may change in future minor versions" if bool
raise "Threadsafe setting cannot be changed once a session is created" if (bool != threadsafe) && Session.instance_created?
@threadsafe = bool
end
##
#
# Return the proc that Capybara will call to run the Rack application.
# The block returned receives a rack app, port, and host/ip and should run a Rack handler
2018-01-13 16:06:03 -05:00
# By default, Capybara will try to use puma.
#
2018-01-13 16:06:03 -05:00
attr_reader :server
##
#
# Set the server to use.
#
# Capybara.server = :webrick
# Capybara.server = :puma, { Silent: true }
#
# @overload server=(name)
# @param [Symbol] name Name of the server type to use
# @overload server=([name, options])
# @param [Symbol] name Name of the server type to use
# @param [Hash] options Options to pass to the server block
# @see register_server
#
def server=(name)
name, options = *name if name.is_a? Array
@server = if options
2018-01-09 17:05:50 -05:00
proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, options) }
else
Capybara.servers[name.to_sym]
end
end
##
#
# @return [Symbol] The name of the driver to use by default
#
def default_driver
@default_driver || :rack_test
end
##
#
# @return [Symbol] The name of the driver used when JavaScript is needed
#
def javascript_driver
@javascript_driver || :selenium
end
2018-01-09 17:05:50 -05:00
def deprecate(method, alternate_method, once = false)
@deprecation_notified ||= {}
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
2018-01-09 17:05:50 -05:00
@deprecation_notified[method] = true
end
end
2018-01-09 17:05:50 -05:00
end