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, #execute_script, #has_shortcircuit_timeout?, #wait?, #wait_until, #within_frame

Constructor Details

#initialize(app) ⇒ RackTest

Returns a new instance of RackTest.

Raises:

  • (ArgumentError)


192
193
194
195
# File 'lib/capybara/driver/rack_test_driver.rb', line 192

def initialize(app)
  raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



187
188
189
# File 'lib/capybara/driver/rack_test_driver.rb', line 187

def app
  @app
end

Instance Method Details

#bodyObject Also known as: source



229
230
231
# File 'lib/capybara/driver/rack_test_driver.rb', line 229

def body
  @body ||= response.body
end

#cleanup!Object



238
239
240
# File 'lib/capybara/driver/rack_test_driver.rb', line 238

def cleanup!
  clear_cookies
end

#current_urlObject



207
208
209
# File 'lib/capybara/driver/rack_test_driver.rb', line 207

def current_url
  request.url rescue ""
end

#delete(*args, &block) ⇒ Object



245
# File 'lib/capybara/driver/rack_test_driver.rb', line 245

def delete(*args, &block); reset_cache; super; end

#find(selector) ⇒ Object



225
226
227
# File 'lib/capybara/driver/rack_test_driver.rb', line 225

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

#follow_redirects!Object



247
248
249
250
251
252
# File 'lib/capybara/driver/rack_test_driver.rb', line 247

def follow_redirects!
  5.times do
    follow_redirect! if response.redirect?
  end
  raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects." if response.redirect?
end

#get(*args, &block) ⇒ Object



242
# File 'lib/capybara/driver/rack_test_driver.rb', line 242

def get(*args, &block); reset_cache; super; end

#htmlObject



233
234
235
# File 'lib/capybara/driver/rack_test_driver.rb', line 233

def html
  @html ||= Nokogiri::HTML(body)
end

#post(*args, &block) ⇒ Object



243
# File 'lib/capybara/driver/rack_test_driver.rb', line 243

def post(*args, &block); reset_cache; super; end

#process(method, path, attributes = {}) ⇒ Object



201
202
203
204
205
# File 'lib/capybara/driver/rack_test_driver.rb', line 201

def process(method, path, attributes = {})
  return if path.gsub(/^#{request_path}/, '') =~ /^#/
  send(method, path, attributes, env)
  follow_redirects!
end

#put(*args, &block) ⇒ Object



244
# File 'lib/capybara/driver/rack_test_driver.rb', line 244

def put(*args, &block); reset_cache; super; end

#response_headersObject



211
212
213
# File 'lib/capybara/driver/rack_test_driver.rb', line 211

def response_headers
  response.headers
end

#status_codeObject



215
216
217
# File 'lib/capybara/driver/rack_test_driver.rb', line 215

def status_code
  response.status
end

#submit(method, path, attributes) ⇒ Object



219
220
221
222
223
# File 'lib/capybara/driver/rack_test_driver.rb', line 219

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

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



197
198
199
# File 'lib/capybara/driver/rack_test_driver.rb', line 197

def visit(path, attributes = {})
  process(:get, path, attributes)
end