2016-03-07 16:52:19 -08:00
|
|
|
# frozen_string_literal: true
|
2011-04-05 17:42:12 +02:00
|
|
|
require 'rack/test'
|
|
|
|
require 'rack/utils'
|
|
|
|
require 'mime/types'
|
|
|
|
require 'nokogiri'
|
|
|
|
require 'cgi'
|
|
|
|
|
|
|
|
class Capybara::RackTest::Driver < Capybara::Driver::Base
|
2011-09-04 20:26:14 +02:00
|
|
|
DEFAULT_OPTIONS = {
|
2012-07-12 16:57:27 +02:00
|
|
|
:respect_data_method => false,
|
2012-07-12 17:03:28 +02:00
|
|
|
:follow_redirects => true,
|
|
|
|
:redirect_limit => 5
|
2011-09-04 20:26:14 +02:00
|
|
|
}
|
2011-04-25 11:35:57 +02:00
|
|
|
attr_reader :app, :options
|
2011-04-05 17:42:12 +02:00
|
|
|
|
2011-04-25 11:35:57 +02:00
|
|
|
def initialize(app, options={})
|
2011-04-05 17:42:12 +02:00
|
|
|
raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
|
|
|
|
@app = app
|
2011-09-04 20:26:14 +02:00
|
|
|
@options = DEFAULT_OPTIONS.merge(options)
|
2011-04-05 17:42:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def browser
|
2011-08-30 11:20:29 +02:00
|
|
|
@browser ||= Capybara::RackTest::Browser.new(self)
|
2011-04-05 17:42:12 +02:00
|
|
|
end
|
|
|
|
|
2012-07-12 16:57:27 +02:00
|
|
|
def follow_redirects?
|
|
|
|
@options[:follow_redirects]
|
|
|
|
end
|
|
|
|
|
2012-07-12 17:03:28 +02:00
|
|
|
def redirect_limit
|
|
|
|
@options[:redirect_limit]
|
|
|
|
end
|
|
|
|
|
2011-04-05 17:42:12 +02:00
|
|
|
def response
|
|
|
|
browser.last_response
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
|
|
|
browser.last_request
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit(path, attributes = {})
|
|
|
|
browser.visit(path, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def submit(method, path, attributes)
|
|
|
|
browser.submit(method, path, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow(method, path, attributes = {})
|
|
|
|
browser.follow(method, path, attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_url
|
|
|
|
browser.current_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def response_headers
|
|
|
|
response.headers
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_code
|
|
|
|
response.status
|
|
|
|
end
|
|
|
|
|
2013-02-19 09:03:26 -08:00
|
|
|
def find_xpath(selector)
|
|
|
|
browser.find(:xpath, selector)
|
|
|
|
end
|
2016-03-30 20:27:29 +02:00
|
|
|
|
2013-02-19 09:03:26 -08:00
|
|
|
def find_css(selector)
|
|
|
|
browser.find(:css,selector)
|
2011-04-05 17:42:12 +02:00
|
|
|
end
|
2016-03-30 20:27:29 +02:00
|
|
|
|
2012-09-10 03:05:17 +02:00
|
|
|
def html
|
|
|
|
browser.html
|
2011-04-05 17:42:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def dom
|
|
|
|
browser.dom
|
|
|
|
end
|
2016-03-30 20:27:29 +02:00
|
|
|
|
2013-02-06 21:36:55 +02:00
|
|
|
def title
|
|
|
|
browser.title
|
|
|
|
end
|
2011-04-05 17:42:12 +02:00
|
|
|
|
|
|
|
def reset!
|
|
|
|
@browser = nil
|
|
|
|
end
|
|
|
|
|
2016-04-04 12:49:44 -07:00
|
|
|
# @deprecated This method is being removed
|
|
|
|
def browser_initialized?
|
|
|
|
super && !@browser.nil?
|
|
|
|
end
|
|
|
|
|
2011-04-05 17:42:12 +02:00
|
|
|
def get(*args, &block); browser.get(*args, &block); end
|
|
|
|
def post(*args, &block); browser.post(*args, &block); end
|
|
|
|
def put(*args, &block); browser.put(*args, &block); end
|
|
|
|
def delete(*args, &block); browser.delete(*args, &block); end
|
2011-04-08 16:14:05 +01:00
|
|
|
def header(key, value); browser.header(key, value); end
|
2011-04-05 17:42:12 +02:00
|
|
|
end
|