Module: Merb::Test::Rspec::ControllerMatchers
- Defined in:
- lib/merb-core/test/matchers/controller_matchers.rb
Defined Under Namespace
Classes: BeMissing, BeRedirect, BeSuccess, RedirectTo
Instance Method Summary collapse
-
#be_missing ⇒ Object
(also: #be_client_error)
Passes if the request that generated the target was missing, or the target is a client-side error (400 level) response code.
-
#redirect ⇒ Object
(also: #be_redirection)
Passes if the target was redirected, or the target is a redirection (300 level) response code.
-
#redirect_to(expected) ⇒ Object
(also: #be_redirection_to)
Passes if the target was redirected to the expected location.
-
#respond_successfully ⇒ Object
(also: #be_successful)
Passes if the request that generated the target was successful, or the target is a success (200 level) response code.
Instance Method Details
#be_missing ⇒ Object Also known as: be_client_error
Passes if the request that generated the target was missing, or the target is a client-side error (400 level) response code.
Examples
# Passes if the controller call was unknown or not understood
controller.should be_missing
# Also passes if the target is a response code
controller.status.should be_missing
Notes
valid HTTP Client Error codes:
-
400: Bad Request
-
401: Unauthorized
-
402: Payment Required
-
403: Forbidden
-
404: Not Found
-
405: Method Not Allowed
-
406: Not Acceptable
-
407: Proxy Authentication Required
-
408: Request Timeout
-
409: Conflict
-
410: Gone
-
411: Length Required
-
412: Precondition Failed
-
413: Request Entity Too Large
-
414: Request-URI Too Long
-
415: Unsupported Media Type
-
416: Requested Range Not Satisfiable
-
417: Expectation Failed
-
422: Unprocessable Entity
– status codes based on: cheat.errtheblog.com/s/http_status_codes/
264 265 266 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 264 def be_missing BeMissing.new end |
#redirect ⇒ Object Also known as: be_redirection
Passes if the target was redirected, or the target is a redirection (300 level) response code.
Examples
# Passes if the controller was redirected
controller.should redirect
# Also works if the target is the response code
controller.status.should redirect
Notes
valid HTTP Redirection codes:
-
300: Multiple Choices
-
301: Moved Permanently
-
302: Moved Temporarily (HTTP/1.0)
-
302: Found (HTTP/1.1)
-
303: See Other (HTTP/1.1)
-
304: Not Modified
-
305: Use Proxy
-
307: Temporary Redirect
– status codes based on: cheat.errtheblog.com/s/http_status_codes/
183 184 185 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 183 def redirect BeRedirect.new end |
#redirect_to(expected) ⇒ Object Also known as: be_redirection_to
Passes if the target was redirected to the expected location.
Paramters
- expected<String>
-
A relative or absolute url.
Examples
# Passes if the controller was redirected to http://example.com/
controller.should redirect_to('http://example.com/')
197 198 199 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 197 def redirect_to(expected) RedirectTo.new(expected) end |
#respond_successfully ⇒ Object Also known as: be_successful
Passes if the request that generated the target was successful, or the target is a success (200 level) response code.
Examples
# Passes if the controller call was successful
controller.should respond_successfully
# Also works if the target is the response code
controller.status.should respond_successfully
Notes
valid HTTP Success codes:
-
200: OK
-
201: Created
-
202: Accepted
-
203: Non-Authoritative Information
-
204: No Content
-
205: Reset Content
-
206: Partial Content
-
207: Multi-Status
– status codes based on: cheat.errtheblog.com/s/http_status_codes/
225 226 227 |
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 225 def respond_successfully BeSuccess.new end |