Class: Capybara::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capybara/config.rb

Constant Summary

OPTIONS =
%i[app reuse_server threadsafe default_wait_time server default_driver javascript_driver].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config



21
22
23
# File 'lib/capybara/config.rb', line 21

def initialize
  @session_options = Capybara::SessionConfig.new
end

Instance Attribute Details

#appObject

Returns the value of attribute app



12
13
14
# File 'lib/capybara/config.rb', line 12

def app
  @app
end

#default_driverSymbol

Returns The name of the driver to use by default

Returns:

  • (Symbol)

    The name of the driver to use by default



71
72
73
# File 'lib/capybara/config.rb', line 71

def default_driver
  @default_driver || :rack_test
end

#javascript_driverSymbol

Returns The name of the driver used when JavaScript is needed

Returns:

  • (Symbol)

    The name of the driver used when JavaScript is needed



79
80
81
# File 'lib/capybara/config.rb', line 79

def javascript_driver
  @javascript_driver || :selenium
end

#reuse_serverObject

Returns the value of attribute reuse_server



13
14
15
# File 'lib/capybara/config.rb', line 13

def reuse_server
  @reuse_server
end

#session_optionsObject (readonly)

Returns the value of attribute session_options



14
15
16
# File 'lib/capybara/config.rb', line 14

def session_options
  @session_options
end

#threadsafeObject

Returns the value of attribute threadsafe



13
14
15
# File 'lib/capybara/config.rb', line 13

def threadsafe
  @threadsafe
end

Instance Method Details

#deprecate(method, alternate_method, once = false) ⇒ Object



83
84
85
86
87
# File 'lib/capybara/config.rb', line 83

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]
  @deprecation_notified[method] = true
end

#serverObject

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 By default, Capybara will try to run webrick.

Raises:

  • (ArgumentError)


39
40
41
42
# File 'lib/capybara/config.rb', line 39

def server
  raise ArgumentError, "Capybara#server no longer accepts a block" if block_given?
  @server
end

#server=(name) ⇒ Object #server=([name, options]) ⇒ Object

Set the server to use.

Capybara.server = :webrick
Capybara.server = :puma, { Silent: true }

Overloads:

  • #server=(name) ⇒ Object

    Parameters:

    • name (Symbol)

      Name of the server type to use

  • #server=([name, options]) ⇒ Object

    Parameters:

    • name (Symbol)

      Name of the server type to use

    • options (Hash)

      Options to pass to the server block

See Also:



58
59
60
61
62
63
64
65
# File 'lib/capybara/config.rb', line 58

def server=(name)
  name, options = *name if name.is_a? Array
  @server = if options
    proc { |app, port, host| Capybara.servers[name.to_sym].call(app, port, host, options) }
  else
    Capybara.servers[name.to_sym]
  end
end