Sha256: 7e621f896d96f4019aca46ae8938272c8cc06937c2ea4906fc326f1a32534952

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

# 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 = {
    respect_data_method: false,
    follow_redirects: true,
    redirect_limit: 5
  }.freeze
  attr_reader :app, :options

  def initialize(app, **options)
    raise ArgumentError, "rack-test requires a rack application, but none was given" unless app
    @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

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

  def refresh
    browser.refresh
  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

  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
  def header(key, value); browser.header(key, value); end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
tdiary-5.0.9 vendor/bundle/gems/capybara-3.2.1/lib/capybara/rack_test/driver.rb
capybara-3.3.1 lib/capybara/rack_test/driver.rb
capybara-3.3.0 lib/capybara/rack_test/driver.rb
capybara-3.2.1 lib/capybara/rack_test/driver.rb
capybara-3.2.0 lib/capybara/rack_test/driver.rb
capybara-3.1.1 lib/capybara/rack_test/driver.rb
capybara-3.1.0 lib/capybara/rack_test/driver.rb
capybara-3.0.3 lib/capybara/rack_test/driver.rb
capybara-3.0.2 lib/capybara/rack_test/driver.rb
capybara-3.0.1 lib/capybara/rack_test/driver.rb
capybara-3.0.0 lib/capybara/rack_test/driver.rb
capybara-3.0.0.rc2 lib/capybara/rack_test/driver.rb
capybara-3.0.0.rc1 lib/capybara/rack_test/driver.rb