Class: Webrat::MerbSession

Inherits:
Session show all
Includes:
Merb::Test::MakeRequest
Defined in:
lib/webrat/merb.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, #open_in_browser, #page_scope, #reloads, #request_page, #rewrite_css_and_image_references, #save_and_open_page, #saved_page_dir, #scopes, #simulate, #success_code?, #visit, #within, #xml_content_type?

Methods included from Logging

#debug_log, #logger

Constructor Details

This class inherits a constructor from Webrat::Session

Instance Attribute Details

#responseObject

Returns the value of attribute response.



14
15
16
# File 'lib/webrat/merb.rb', line 14

def response
  @response
end

Instance Method Details

#delete(url, data, headers = nil) ⇒ Object



28
29
30
# File 'lib/webrat/merb.rb', line 28

def delete(url, data, headers = nil)
  do_request(url, data, headers, "DELETE")
end

#do_request(url, data, headers, method) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/webrat/merb.rb', line 40

def do_request(url, data, headers, method)
  @response = request(url, 
    :params => (data && data.any?) ? data : nil, 
    :headers => headers,
    :method => method)
  follow_redirect
end

#follow_redirectObject



48
49
50
# File 'lib/webrat/merb.rb', line 48

def follow_redirect
  self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
end

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



16
17
18
# File 'lib/webrat/merb.rb', line 16

def get(url, data, headers = nil)
  do_request(url, data, headers, "GET")
end

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



20
21
22
# File 'lib/webrat/merb.rb', line 20

def post(url, data, headers = nil)
  do_request(url, data, headers, "POST")
end

#put(url, data, headers = nil) ⇒ Object



24
25
26
# File 'lib/webrat/merb.rb', line 24

def put(url, data, headers = nil)
  do_request(url, data, headers, "PUT")
end

#response_bodyObject



32
33
34
# File 'lib/webrat/merb.rb', line 32

def response_body
  @response.body.to_s
end

#response_codeObject



36
37
38
# File 'lib/webrat/merb.rb', line 36

def response_code
  @response.status
end