Class: Capybara::Mechanize::Browser

Inherits:
RackTest::Browser
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capybara/mechanize/browser.rb

Defined Under Namespace

Classes: ResponseProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Browser

Returns a new instance of Browser.



12
13
14
15
16
17
# File 'lib/capybara/mechanize/browser.rb', line 12

def initialize(driver)
  @agent = ::Mechanize.new
  @agent.redirect_ok = false
  @agent.user_agent = default_user_agent
  super
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



70
71
72
# File 'lib/capybara/mechanize/browser.rb', line 70

def agent
  @agent
end

Instance Method Details

#current_urlObject



25
26
27
# File 'lib/capybara/mechanize/browser.rb', line 25

def current_url
  last_request_remote? ? remote_response.current_url : super
end

#find(selector) ⇒ Object



66
67
68
# File 'lib/capybara/mechanize/browser.rb', line 66

def find(selector)
  dom.xpath(selector).map { |node| Capybara::Mechanize::Node.new(self, node) }
end

#last_responseObject



29
30
31
# File 'lib/capybara/mechanize/browser.rb', line 29

def last_response
  last_request_remote? ? remote_response : super
end

#remote?(url) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/capybara/mechanize/browser.rb', line 52

def remote?(url)
  if Capybara.app_host
    true
  else
    host = URI.parse(url).host

    if host.nil?
      last_request_remote?
    else
      !Capybara::Mechanize.local_hosts.include?(host)
    end
  end
end

#reset_host!Object



19
20
21
22
23
# File 'lib/capybara/mechanize/browser.rb', line 19

def reset_host!
  @last_remote_uri = nil
  @last_request_remote = nil
  super
end