Override the default Response implementation to include methods useful for testing.
Methods
- add_cookie
- body
- content_type
- content_type=
- redirect?
- redirect_uri
- response_cookie
- send_cookie
- status_ok?
Attributes
| [RW] | response_cookies | The Response cookies. |
| [RW] | response_headers | The Response headers. |
| [RW] | status | The Response status. |
Public Instance methods
Add a cookie to the response. Better use this method to avoid precreating the cookies array for every request.
Examples
add_cookie(‘nsid’, ‘gmosx’) add_cookie(Cookie.new(‘nsid’, ‘gmosx’)
This method is also aliased as
send_cookie
[ show source ]
# File lib/raw/context/response.rb, line 40
40: def add_cookie(cookie, value = nil)
41: if value
42: (@response_cookies ||= []) << Cookie.new(cookie, value)
43: else
44: (@response_cookies ||= []) << cookie
45: end
46: end
Return the output buffer.
[ show source ]
# File lib/raw/context/response.rb, line 51
51: def body
52: @output_buffer
53: end
Return the content type for this response.
[ show source ]
# File lib/raw/context/response.rb, line 21
21: def content_type
22: @response_headers["Content-Type"]
23: end
Set the content type for this response.
[ show source ]
# File lib/raw/context/response.rb, line 27
27: def content_type=(ctype)
28: @response_headers["Content-Type"] = ctype
29: end
[ show source ]
# File lib/raw/test/context.rb, line 24
24: def redirect?
25: (300..399).include?(@status)
26: end
[ show source ]
# File lib/raw/test/context.rb, line 28
28: def redirect_uri
29: @response_headers['location']
30: end
[ show source ]
# File lib/raw/test/context.rb, line 32
32: def response_cookie(name)
33: return nil unless @response_cookies
34: @response_cookies.find { |c| c.name == name }
35: end
Alias for #add_cookie
[ show source ]
# File lib/raw/test/context.rb, line 20
20: def status_ok?
21: @status == 200
22: end