Module: Merb::Test::Rspec::ControllerMatchers

Defined in:
lib/merb-core/test/matchers/controller_matchers.rb

Defined Under Namespace

Classes: BeMissing, BeRedirect, BeSuccess, Provide, RedirectTo

Instance Method Summary collapse

Instance Method Details

#be_missingObject 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/



302
303
304
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 302

def be_missing
  BeMissing.new
end

#provide(expected) ⇒ Object

Passes if the controller actually provides the target format

Parameters

expected<Symbol>

A format to check

Examples

ControllerClass.should provide( :html )
controller_instance.should provide( :xml )


316
317
318
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 316

def provide( expected )
  Provide.new( expected )
end

#redirectObject 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/



221
222
223
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 221

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/')


235
236
237
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 235

def redirect_to(expected)
  RedirectTo.new(expected)
end

#respond_successfullyObject 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/



263
264
265
# File 'lib/merb-core/test/matchers/controller_matchers.rb', line 263

def respond_successfully
  BeSuccess.new
end