Class: Webrat::MechanizeAdapter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/webrat/adapters/mechanize.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MechanizeAdapter

Returns a new instance of MechanizeAdapter.



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

def initialize(*args)
end

Instance Attribute Details

#responseObject Also known as: page

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#absolute_url(url) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/webrat/adapters/mechanize.rb', line 48

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



17
18
19
# File 'lib/webrat/adapters/mechanize.rb', line 17

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

#mechanizeObject



42
43
44
# File 'lib/webrat/adapters/mechanize.rb', line 42

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

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



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webrat/adapters/mechanize.rb', line 21

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:



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

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

#response_bodyObject



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

def response_body
  @response.content
end

#response_codeObject



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

def response_code
  @response.code.to_i
end