Class: Capybara::RackTest::Browser

### Home Classes Methods

### In Files

- lib/capybara/rack_test/browser.rb

### Parent

Object

### Methods

- ::new
- #app
- #build_rack_mock_session
- #current_url
- #dom
- #find
- #follow
- #html
- #options
- #process
- #process_and_follow_redirects
- #request_path
- #reset_cache!
- #reset_host!
- #submit
- #title
- #visit

### Included Modules

- ::Rack::Test::Methods

### Files

- another_test_file.txt
- test_file.txt

### Class/Module Index

Quicksearch

- Capybara
- Capybara::Ambiguous
- Capybara::CapybaraError
- Capybara::DSL
- Capybara::Driver
- Capybara::Driver::Base
- Capybara::Driver::Node
- Capybara::DriverNotFoundError
- Capybara::ElementNotFound
- Capybara::ExpectationNotMet
- Capybara::Features
- Capybara::FileNotFound
- Capybara::FrozenInTime
- Capybara::Helpers
- Capybara::InfiniteRedirectError
- Capybara::ModalNotFound
- Capybara::Node
- Capybara::Node::Actions
- Capybara::Node::Base
- Capybara::Node::Document
- Capybara::Node::DocumentMatchers
- Capybara::Node::Element
- Capybara::Node::Finders
- Capybara::Node::Matchers
- Capybara::Node::Simple
- Capybara::NotSupportedByDriverError
- Capybara::Queries
- Capybara::Queries::BaseQuery
- Capybara::Queries::TextQuery
- Capybara::Queries::TitleQuery
- Capybara::Query
- Capybara::RSpecMatchers
- Capybara::RSpecMatchers::BecomeClosed
- Capybara::RSpecMatchers::HaveSelector
- Capybara::RSpecMatchers::HaveText
- Capybara::RSpecMatchers::HaveTitle
- Capybara::RSpecMatchers::Matcher
- Capybara::RackTest
- Capybara::RackTest::Browser
- Capybara::RackTest::CSSHandlers
- Capybara::RackTest::Driver
- Capybara::RackTest::Form
- Capybara::RackTest::Form::NilUploadedFile
- Capybara::RackTest::Node
- Capybara::ReadOnlyElementError
- Capybara::Result
- Capybara::ScopeError
- Capybara::Selector
- Capybara::Selector::Filter
- Capybara::Selenium
- Capybara::Selenium::Driver
- Capybara::Selenium::Node
- Capybara::Server
- Capybara::Server::Middleware
- Capybara::Session
- Capybara::SpecHelper
- Capybara::UnselectNotAllowed
- Capybara::Window
- Capybara::WindowError
- TestApp
- TestApp::TestAppError
- Object

No matching classes.

# Capybara::RackTest::Browser

### Attributes

current_host[RW]
driver[R]

### Public Class Methods

new(driver) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 7
    def initialize(driver)
      @driver = driver
    end

### Public Instance Methods

app() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 11
    def app
      driver.app
    end

current_url() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 63
    def current_url
      last_request.url
    rescue Rack::Test::Error
      ""
    end

dom() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 80
    def dom
      @dom ||= Capybara::HTML(html)
    end

find(format, selector) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 84
    def find(format, selector)
      if format==:css
        dom.css(selector, Capybara::RackTest::CSSHandlers.new)
      else
        dom.xpath(selector)
      end.map { |node| Capybara::RackTest::Node.new(self, node) }
    end

follow(method, path, attributes = {}) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 29
    def follow(method, path, attributes = {})
      return if path.gsub(/^#{request_path}/, '').start_with?('#')
      process_and_follow_redirects(method, path, attributes, {'HTTP_REFERER' => current_url})
    end

html() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 92
    def html
      last_response.body
    rescue Rack::Test::Error
      ""
    end

options() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 15
    def options
      driver.options
    end

process(method, path, attributes = {}, env = {}) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 44
    def process(method, path, attributes = {}, env = {})
      new_uri = URI.parse(path)
      method.downcase! unless method.is_a? Symbol

      new_uri.path = request_path if path.start_with?("?")
      new_uri.path = "/" if new_uri.path.empty?
      new_uri.path = request_path.sub(%(/[^/]*$), '/') + new_uri.path unless new_uri.path.start_with?('/')
      new_uri.scheme ||= @current_scheme
      new_uri.host ||= @current_host
      new_uri.port ||= @current_port unless new_uri.default_port == @current_port

      @current_scheme = new_uri.scheme
      @current_host = new_uri.host
      @current_port = new_uri.port

      reset_cache!
      send(method, new_uri.to_s, attributes, env.merge(options[:headers] || {}))
    end

process_and_follow_redirects(method, path, attributes = {}, env = {}) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 34
    def process_and_follow_redirects(method, path, attributes = {}, env = {})
      process(method, path, attributes, env)
      if driver.follow_redirects?
        driver.redirect_limit.times do
          process(:get, last_response["Location"], {}, env) if last_response.redirect?
        end
        raise Capybara::InfiniteRedirectError, "redirected more than #{driver.redirect_limit} times, check for infinite redirects." if last_response.redirect?
      end
    end

reset_cache!() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 76
    def reset_cache!
      @dom = nil
    end

reset_host!() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 69
    def reset_host!
      uri = URI.parse(Capybara.app_host || Capybara.default_host)
      @current_scheme = uri.scheme
      @current_host = uri.host
      @current_port = uri.port
    end

submit(method, path, attributes) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 24
    def submit(method, path, attributes)
      path = request_path if not path or path.empty?
      process_and_follow_redirects(method, path, attributes, {'HTTP_REFERER' => current_url})
    end

title() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 98
    def title
      dom.xpath("//title").text
    end

visit(path, attributes = {}) click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 19
    def visit(path, attributes = {})
      reset_host!
      process_and_follow_redirects(:get, path, attributes)
    end

### Protected Instance Methods

build_rack_mock_session() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 104
    def build_rack_mock_session
      reset_host! unless current_host
      Rack::MockSession.new(app, current_host)
    end

request_path() click to toggle source

    # File lib/capybara/rack_test/browser.rb, line 109
    def request_path
      last_request.path
    rescue Rack::Test::Error
      "/"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.