Class: Capybara::Typhoeus::Browser

Inherits:
RackTest::Browser
  • Object
show all
Defined in:
lib/capybara/typhoeus/browser.rb

Defined Under Namespace

Classes: LastRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_requestObject (readonly)

Returns the value of attribute last_request.



24
25
26
# File 'lib/capybara/typhoeus/browser.rb', line 24

def last_request
  @last_request
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



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

def last_response
  @last_response
end

#request_bodyObject

Returns the value of attribute request_body.



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

def request_body
  @request_body
end

Instance Method Details

#current_urlObject



38
39
40
# File 'lib/capybara/typhoeus/browser.rb', line 38

def current_url
  last_response ? last_response.effective_url : ""
end

#domObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capybara/typhoeus/browser.rb', line 42

def dom
  @dom ||= begin
    content_type = if last_response
      last_response.headers["Content-Type"].to_s[/\A[^;]+/]
    else
      ""
    end
    if content_type.include? "/xml"
      xml
    else
      Capybara::HTML html
    end
  end
end

#htmlObject



57
58
59
# File 'lib/capybara/typhoeus/browser.rb', line 57

def html
  last_response ? last_response.body : ""
end

#jsonObject



65
66
67
# File 'lib/capybara/typhoeus/browser.rb', line 65

def json
  @json ||= JSON.parse html
end

#refreshObject



33
34
35
36
# File 'lib/capybara/typhoeus/browser.rb', line 33

def refresh
  reset_cache!
  send(last_request.method, last_request.url, last_request.params, last_request.headers)
end

#reset_cache!Object



27
28
29
30
31
# File 'lib/capybara/typhoeus/browser.rb', line 27

def reset_cache!
  @xml = nil
  @json = nil
  super
end

#xmlObject



61
62
63
# File 'lib/capybara/typhoeus/browser.rb', line 61

def xml
  @xml ||= Nokogiri::XML html
end