#120 new
Chad Humphries

[#13885] be_status methods

Reported by Chad Humphries | November 19th, 2007 @ 06:30 AM

response.should be_successful or response.should be_missing are nice but not enough. In too many cases I'm looking for response codes that are neither 200 nor 404.

So how about adding all the status symbols as tests methods?

Controller:

head :unauthorized

Spec:

response.should be_unauthorized

Controller:

head :gone

Spec:

response.should be_gone

And so forth. This code will do it for anything using controller (TestResponse) and integration (CgiResponse) tests:

module ActionController
  # TestResponse for functional, CgiResponse for integration.
  class AbstractResponse
    StatusCodes::SYMBOL_TO_STATUS_CODE.each do |symbol, code|
      define_method("#{symbol}?") { self.response_code == code } unless
instance_methods.include?("#{symbol}?")
    end
  end
end

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins

People watching this ticket