2016-12-15 12:04:01 -05:00
|
|
|
# frozen_string_literal: true
|
2018-01-08 15:23:54 -05:00
|
|
|
|
2016-12-15 12:04:01 -05:00
|
|
|
require 'delegate'
|
|
|
|
|
|
|
|
module Capybara
|
|
|
|
class SessionConfig
|
2018-01-08 15:23:54 -05:00
|
|
|
OPTIONS = %i[always_include_port run_server default_selector default_max_wait_time ignore_hidden_elements
|
|
|
|
automatic_reload match exact exact_text raise_server_errors visible_text_only
|
|
|
|
automatic_label_click enable_aria_label save_path asset_host default_host app_host
|
|
|
|
server_host server_port server_errors].freeze
|
2016-12-15 12:04:01 -05:00
|
|
|
|
2017-05-26 01:23:40 -04:00
|
|
|
attr_accessor(*OPTIONS)
|
2016-12-15 12:04:01 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
#@!method always_include_port
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method run_server
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method default_selector
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method default_max_wait_time
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method ignore_hidden_elements
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method automatic_reload
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method match
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method exact
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method raise_server_errors
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method visible_text_only
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method automatic_label_click
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method enable_aria_label
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method save_path
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method asset_host
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method default_host
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method app_host
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method server_host
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method server_port
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
#@!method server_errors
|
2017-06-07 13:32:01 -04:00
|
|
|
# See {Capybara.configure}
|
2016-12-15 12:04:01 -05:00
|
|
|
|
2017-05-26 01:23:40 -04:00
|
|
|
remove_method :server_host
|
|
|
|
|
2016-12-15 12:04:01 -05:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# @return [String] The IP address bound by default server
|
|
|
|
#
|
|
|
|
def server_host
|
|
|
|
@server_host || '127.0.0.1'
|
|
|
|
end
|
|
|
|
|
2017-05-26 01:23:40 -04:00
|
|
|
remove_method :server_errors=
|
2016-12-15 12:04:01 -05:00
|
|
|
def server_errors=(errors)
|
|
|
|
(@server_errors ||= []).replace(errors.dup)
|
|
|
|
end
|
|
|
|
|
2017-05-26 01:23:40 -04:00
|
|
|
remove_method :app_host=
|
2016-12-15 12:04:01 -05:00
|
|
|
def app_host=(url)
|
2018-01-08 15:23:54 -05:00
|
|
|
raise ArgumentError.new("Capybara.app_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::DEFAULT_PARSER.make_regexp)
|
2016-12-15 12:04:01 -05:00
|
|
|
@app_host = url
|
|
|
|
end
|
|
|
|
|
2017-05-26 01:23:40 -04:00
|
|
|
remove_method :default_host=
|
2016-12-15 12:04:01 -05:00
|
|
|
def default_host=(url)
|
2018-01-08 15:23:54 -05:00
|
|
|
raise ArgumentError.new("Capybara.default_host should be set to a url (http://www.example.com)") unless url.nil? || (url =~ URI::DEFAULT_PARSER.make_regexp)
|
2016-12-15 12:04:01 -05:00
|
|
|
@default_host = url
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_copy(other)
|
|
|
|
super
|
|
|
|
@server_errors = @server_errors.dup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ReadOnlySessionConfig < SimpleDelegator
|
|
|
|
SessionConfig::OPTIONS.each do |m|
|
2017-11-13 16:04:47 -05:00
|
|
|
define_method "#{m}=" do |_|
|
2016-12-15 12:04:01 -05:00
|
|
|
raise "Per session settings are only supported when Capybara.threadsafe == true"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|