Class: Webrat::MechanizeSession

Inherits:
Session show all
Defined in:
lib/webrat/mechanize.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Session

#current_url, #elements

Instance Method Summary collapse

Methods inherited from Session

#automate, #basic_auth, #click_link_within, #current_dom, #current_page, #current_scope, #doc_root, #dom, #exception_caught?, #formatted_error, #header, #headers, #http_accept, #initialize, #internal_redirect?, #page_scope, #redirect?, #redirected_to, #reload, #scopes, #simulate, #success_code?, #visit, #within, #xml_content_type?

Methods included from SaveAndOpenPage

#doc_root, #open_in_browser, #rewrite_css_and_image_references, #save_and_open_page, #saved_page_dir

Methods included from Logging

#debug_log, #logger

Constructor Details

This class inherits a constructor from Webrat::Session

Instance Attribute Details

#responseObject Also known as: page

Returns the value of attribute response.



6
7
8
# File 'lib/webrat/mechanize.rb', line 6

def response
  @response
end

Instance Method Details

#absolute_url(url) ⇒ Object

:nodoc:



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/webrat/mechanize.rb', line 44

def absolute_url(url) #:nodoc:
  current_host, current_path = split_current_url
  if url =~ Regexp.new('^https?://')
    url
  elsif url =~ Regexp.new('^/')
    current_host + url
  elsif url =~ Regexp.new('^\.')
    current_host + absolute_path(current_path, url)
  else
    url
  end
end

#get(url, data, headers_argument_not_used = nil) ⇒ Object



13
14
15
# File 'lib/webrat/mechanize.rb', line 13

def get(url, data, headers_argument_not_used = nil)
  @response = mechanize.get(url, data)
end

#mechanizeObject



38
39
40
# File 'lib/webrat/mechanize.rb', line 38

def mechanize
  @mechanize = WWW::Mechanize.new
end

#post(url, data, headers_argument_not_used = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/webrat/mechanize.rb', line 17

def post(url, data, headers_argument_not_used = nil)
  post_data = data.inject({}) do |memo, param|
    case param.last
    when Hash
      param.last.each {|attribute, value| memo["#{param.first}[#{attribute}]"] = value }
    else
      memo[param.first] = param.last
    end
    memo
  end
  @response = mechanize.post(url, post_data)
end

#request_page(url, http_method, data) ⇒ Object

:nodoc:



9
10
11
# File 'lib/webrat/mechanize.rb', line 9

def request_page(url, http_method, data) #:nodoc:
  super(absolute_url(url), http_method, data)
end

#response_bodyObject



30
31
32
# File 'lib/webrat/mechanize.rb', line 30

def response_body
  @response.content
end

#response_codeObject



34
35
36
# File 'lib/webrat/mechanize.rb', line 34

def response_code
  @response.code.to_i
end