Class: Capybara::Mechanize::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/mechanize/browser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBrowser

Returns a new instance of Browser.



6
7
8
9
10
11
# File 'lib/capybara/mechanize/browser.rb', line 6

def initialize
  @agent = Mechanize.new do |config|
    config.follow_meta_refresh = true
    config.redirection_limit   = 5
  end
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



4
5
6
# File 'lib/capybara/mechanize/browser.rb', line 4

def agent
  @agent
end

Instance Method Details

#been_somewhere?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/capybara/mechanize/browser.rb', line 47

def been_somewhere?
  !@agent.current_page.nil?
end

#delete(url) ⇒ Object



20
# File 'lib/capybara/mechanize/browser.rb', line 20

def delete(url); @agent.delete(url); end

#domObject



39
40
41
# File 'lib/capybara/mechanize/browser.rb', line 39

def dom
  been_somewhere? ? @agent.current_page.root : Nokogiri::HTML(nil)
end

#get(url) ⇒ Object



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

def get(url)  
  referrer = been_somewhere? ? self.url : nil
  @agent.get(url, [], referrer)
end

#headersObject



31
32
33
# File 'lib/capybara/mechanize/browser.rb', line 31

def headers
  been_somewhere? ? @agent.current_page.header : {}
end

#post(url) ⇒ Object



18
# File 'lib/capybara/mechanize/browser.rb', line 18

def post(url); @agent.post(url); end

#put(url) ⇒ Object



19
# File 'lib/capybara/mechanize/browser.rb', line 19

def put(url); @agent.get(url); end

#sourceObject



43
44
45
# File 'lib/capybara/mechanize/browser.rb', line 43

def source
  been_somewhere? ? @agent.current_page.body : ''
end

#status_codeObject



35
36
37
# File 'lib/capybara/mechanize/browser.rb', line 35

def status_code
  been_somewhere? ? @agent.current_page.code.to_i : nil
end

#submit(form) ⇒ Object



21
# File 'lib/capybara/mechanize/browser.rb', line 21

def submit(form); @agent.submit(form); end

#uriObject



23
24
25
# File 'lib/capybara/mechanize/browser.rb', line 23

def uri
  been_somewhere? ? @agent.current_page.uri : nil
end

#urlObject



27
28
29
# File 'lib/capybara/mechanize/browser.rb', line 27

def url
  uri.nil? ? '' : uri.to_s
end