Sha256: 66a4e3f13ac8c6fe42f39e10a1d4573e07058c655c4eea576dd1c4af92293692

Contents?: true

Size: 858 Bytes

Versions: 8

Compression:

Stored size: 858 Bytes

Contents

# some more Rack extensions to help when testing
class Rack::MockResponse

  # TODO checkout Rack::Response::Helpers which implements many of these!

  # these methods help with RSpec specs so we can ask things like:
  #
  #   request('/').should be_successful
  #   request('/').should be_redirect
  #   request('/').should be_error
  #

  def success?
    self.status.to_s.start_with?'2' # 200 status codes are successful
  end

  def redirect?
    self.status.to_s.start_with?'3' # 300 status codes are redirects
  end

  def client_error?
    self.status.to_s.start_with?'4' # 400 status codes are client errors
  end

  def server_error?
    self.status.to_s.start_with?'5' # 500 status codes are server errors
  end

  def error?
    self.status.to_s.start_with?('4') || self.status.to_s.start_with?('5') # 400 & 500 status codes are errors
  end

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
remi-rackbox-1.1.0 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.1 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.2 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.3 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.4 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.5 lib/rackbox/rack/extensions_for_rspec.rb
remi-rackbox-1.1.6 lib/rackbox/rack/extensions_for_rspec.rb
eol_rackbox-1.1.7 lib/rackbox/rack/extensions_for_rspec.rb