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
2018-01-09 17:05:50 -05:00
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
2018-07-23 17:57:22 -04:00
server_host server_port server_errors default_set_options disable_animation test_id
predicates_wait ] . 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
##
2018-01-09 17:05:50 -05:00
# @!method always_include_port
# See {Capybara.configure}
# @!method run_server
# See {Capybara.configure}
# @!method default_selector
# See {Capybara.configure}
# @!method default_max_wait_time
# See {Capybara.configure}
# @!method ignore_hidden_elements
# See {Capybara.configure}
# @!method automatic_reload
# See {Capybara.configure}
# @!method match
# See {Capybara.configure}
# @!method exact
# See {Capybara.configure}
# @!method raise_server_errors
# See {Capybara.configure}
# @!method visible_text_only
# See {Capybara.configure}
# @!method automatic_label_click
# See {Capybara.configure}
# @!method enable_aria_label
# See {Capybara.configure}
# @!method save_path
# See {Capybara.configure}
# @!method asset_host
# See {Capybara.configure}
# @!method default_host
# See {Capybara.configure}
# @!method app_host
# See {Capybara.configure}
# @!method server_host
# See {Capybara.configure}
# @!method server_port
# See {Capybara.configure}
# @!method server_errors
# See {Capybara.configure}
2018-05-18 11:22:14 -04:00
# @!method default_set_options
# See {Capybara.configure}
2018-05-16 23:04:24 -04:00
# @!method disable_animation
# See {Capybara.configure}
2018-07-19 12:50:21 -04:00
# @!method test_id
# 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-02-27 14:44:29 -05:00
raise ArgumentError , " Capybara.app_host should be set to a url (http://www.example.com). Attempted to set #{ url . inspect } . " if url && 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-02-27 14:44:29 -05:00
raise ArgumentError , " Capybara.default_host should be set to a url (http://www.example.com). Attempted to set #{ url . inspect } . " if url && url !~ URI :: DEFAULT_PARSER . make_regexp
2016-12-15 12:04:01 -05:00
@default_host = url
end
2018-05-16 23:04:24 -04:00
remove_method :disable_animation =
def disable_animation = ( bool )
2018-07-10 17:18:39 -04:00
warn 'Capybara.disable_animation is a beta feature - it may change/disappear in a future point version' if bool
2018-05-16 23:04:24 -04:00
@disable_animation = bool
end
2018-07-19 12:50:21 -04:00
remove_method :test_id =
##
#
# Set an attribue to be optionally matched against the locator for builtin selector types.
# This attribute will be checked by builtin selector types whenever id would normally be checked.
# If `nil` then it will be ignored.
#
# @params [String, Symbol, nil] id Name of the attribute to use as the test id
#
def test_id = ( id )
@test_id = id & . to_sym
end
2016-12-15 12:04:01 -05:00
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 | _ |
2018-07-10 17:18:39 -04:00
raise 'Per session settings are only supported when Capybara.threadsafe == true'
2016-12-15 12:04:01 -05:00
end
end
end
2018-01-09 17:05:50 -05:00
end