Class: Capybara::RackTest::Driver

Inherits:
Driver::Base show all
Defined in:
lib/capybara/rack_test/driver.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  respect_data_method: false,
  follow_redirects: true,
  redirect_limit: 5
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Driver::Base

#accept_modal, #active_element, #close_window, #current_window_handle, #dismiss_modal, #evaluate_async_script, #evaluate_script, #execute_script, #frame_title, #frame_url, #fullscreen_window, #go_back, #go_forward, #maximize_window, #needs_server?, #no_such_window_error, #open_new_window, #resize_window_to, #save_screenshot, #send_keys, #session_options, #switch_to_frame, #switch_to_window, #wait?, #window_handles, #window_size

Constructor Details

#initialize(app, **options) ⇒ Driver

Returns a new instance of Driver.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/capybara/rack_test/driver.rb', line 17

def initialize(app, **options)
  raise ArgumentError, 'rack-test requires a rack application, but none was given' unless app

  super()
  @app = app
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



15
16
17
# File 'lib/capybara/rack_test/driver.rb', line 15

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/capybara/rack_test/driver.rb', line 15

def options
  @options
end

Instance Method Details

#browserObject



25
26
27
# File 'lib/capybara/rack_test/driver.rb', line 25

def browser
  @browser ||= Capybara::RackTest::Browser.new(self)
end

#current_urlObject



61
62
63
# File 'lib/capybara/rack_test/driver.rb', line 61

def current_url
  browser.current_url
end

#deleteObject



104
# File 'lib/capybara/rack_test/driver.rb', line 104

def delete(...); browser.delete(...); end

#domObject



89
90
91
# File 'lib/capybara/rack_test/driver.rb', line 89

def dom
  browser.dom
end

#find_css(selector) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/capybara/rack_test/driver.rb', line 77

def find_css(selector)
  browser.find(:css, selector)
rescue Nokogiri::CSS::SyntaxError
  raise unless selector.include?(' i]')

  raise ArgumentError, "This driver doesn't support case insensitive attribute matching when using CSS base selectors"
end

#find_xpath(selector) ⇒ Object



73
74
75
# File 'lib/capybara/rack_test/driver.rb', line 73

def find_xpath(selector)
  browser.find(:xpath, selector)
end

#follow(method, path, **attributes) ⇒ Object



57
58
59
# File 'lib/capybara/rack_test/driver.rb', line 57

def follow(method, path, **attributes)
  browser.follow(method, path, attributes)
end

#follow_redirects?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/capybara/rack_test/driver.rb', line 29

def follow_redirects?
  @options[:follow_redirects]
end

#getObject



101
# File 'lib/capybara/rack_test/driver.rb', line 101

def get(...); browser.get(...); end

#header(key, value) ⇒ Object



105
# File 'lib/capybara/rack_test/driver.rb', line 105

def header(key, value); browser.header(key, value); end

#htmlObject



85
86
87
# File 'lib/capybara/rack_test/driver.rb', line 85

def html
  browser.html
end

#invalid_element_errorsObject



107
108
109
# File 'lib/capybara/rack_test/driver.rb', line 107

def invalid_element_errors
  [Capybara::RackTest::Errors::StaleElementReferenceError]
end

#postObject



102
# File 'lib/capybara/rack_test/driver.rb', line 102

def post(...); browser.post(...); end

#putObject



103
# File 'lib/capybara/rack_test/driver.rb', line 103

def put(...); browser.put(...); end

#redirect_limitObject



33
34
35
# File 'lib/capybara/rack_test/driver.rb', line 33

def redirect_limit
  @options[:redirect_limit]
end

#refreshObject



49
50
51
# File 'lib/capybara/rack_test/driver.rb', line 49

def refresh
  browser.refresh
end

#requestObject



41
42
43
# File 'lib/capybara/rack_test/driver.rb', line 41

def request
  browser.last_request
end

#reset!Object



97
98
99
# File 'lib/capybara/rack_test/driver.rb', line 97

def reset!
  @browser = nil
end

#responseObject



37
38
39
# File 'lib/capybara/rack_test/driver.rb', line 37

def response
  browser.last_response
end

#response_headersObject



65
66
67
# File 'lib/capybara/rack_test/driver.rb', line 65

def response_headers
  response.headers
end

#status_codeObject



69
70
71
# File 'lib/capybara/rack_test/driver.rb', line 69

def status_code
  response.status
end

#submit(method, path, attributes) ⇒ Object



53
54
55
# File 'lib/capybara/rack_test/driver.rb', line 53

def submit(method, path, attributes)
  browser.submit(method, path, attributes)
end

#titleObject



93
94
95
# File 'lib/capybara/rack_test/driver.rb', line 93

def title
  browser.title
end

#visit(path, **attributes) ⇒ Object



45
46
47
# File 'lib/capybara/rack_test/driver.rb', line 45

def visit(path, **attributes)
  browser.visit(path, **attributes)
end