1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/rack_test/driver.rb

101 lines
1.8 KiB
Ruby
Raw Normal View History

2016-03-07 19:52:19 -05:00
# frozen_string_literal: true
require 'rack/test'
require 'rack/utils'
require 'mini_mime'
require 'nokogiri'
require 'cgi'
class Capybara::RackTest::Driver < Capybara::Driver::Base
DEFAULT_OPTIONS = {
2016-10-04 14:10:29 -04:00
respect_data_method: false,
follow_redirects: true,
redirect_limit: 5
}
attr_reader :app, :options
2016-08-17 19:14:39 -04:00
def initialize(app, **options)
raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
2017-05-28 11:54:55 -04:00
@session = nil
@app = app
@options = DEFAULT_OPTIONS.merge(options)
end
def browser
@browser ||= Capybara::RackTest::Browser.new(self)
end
def follow_redirects?
@options[:follow_redirects]
end
def redirect_limit
@options[:redirect_limit]
end
def response
browser.last_response
end
def request
browser.last_request
end
2017-05-01 21:39:08 -04:00
def visit(path, **attributes)
browser.visit(path, attributes)
end
2017-07-04 18:14:55 -04:00
def refresh
browser.refresh
end
def submit(method, path, attributes)
browser.submit(method, path, attributes)
end
2017-05-01 21:39:08 -04:00
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
def find_xpath(selector)
browser.find(:xpath, selector)
end
def find_css(selector)
browser.find(:css,selector)
end
def html
browser.html
end
def dom
browser.dom
end
def title
browser.title
end
def reset!
@browser = nil
end
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 11:14:05 -04:00
def header(key, value); browser.header(key, value); end
end