Class: Capybara::Driver::RackTest

Inherits:
Base
  • Object
show all
Includes:
Rack::Test::Methods
Defined in:
lib/capybara/driver/rack_test_driver.rb

Defined Under Namespace

Classes: Form, Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#evaluate_script, #wait?

Constructor Details

#initialize(app) ⇒ RackTest

Returns a new instance of RackTest.



137
138
139
# File 'lib/capybara/driver/rack_test_driver.rb', line 137

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



131
132
133
# File 'lib/capybara/driver/rack_test_driver.rb', line 131

def app
  @app
end

#bodyObject (readonly) Also known as: source

Returns the value of attribute body.



131
132
133
# File 'lib/capybara/driver/rack_test_driver.rb', line 131

def body
  @body
end

#htmlObject (readonly)

Returns the value of attribute html.



131
132
133
# File 'lib/capybara/driver/rack_test_driver.rb', line 131

def html
  @html
end

Instance Method Details

#current_urlObject



148
149
150
# File 'lib/capybara/driver/rack_test_driver.rb', line 148

def current_url
  request.url rescue ""
end

#find(selector) ⇒ Object



163
164
165
# File 'lib/capybara/driver/rack_test_driver.rb', line 163

def find(selector)
  html.xpath(selector).map { |node| Node.new(self, node) }
end

#response_headersObject



152
153
154
# File 'lib/capybara/driver/rack_test_driver.rb', line 152

def response_headers
  response.headers
end

#submit(method, path, attributes) ⇒ Object



156
157
158
159
160
161
# File 'lib/capybara/driver/rack_test_driver.rb', line 156

def submit(method, path, attributes)
  path = current_path if not path or path.empty? 
  send(method, path, attributes)
  follow_redirects!
  cache_body
end

#visit(path, attributes = {}) ⇒ Object



141
142
143
144
145
146
# File 'lib/capybara/driver/rack_test_driver.rb', line 141

def visit(path, attributes = {})
  return if path.gsub(/^#{current_path}/, '') =~ /^#/
  get(path, attributes)
  follow_redirects!
  cache_body
end