Class: Rack::MockResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rackbox/rack/extensions_for_rspec.rb

Overview

some more Rack extensions to help when testing

Instance Method Summary collapse

Instance Method Details

#client_error?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rackbox/rack/extensions_for_rspec.rb', line 21

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

#error?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rackbox/rack/extensions_for_rspec.rb', line 29

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

#redirect?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rackbox/rack/extensions_for_rspec.rb', line 17

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

#server_error?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rackbox/rack/extensions_for_rspec.rb', line 25

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

#success?Boolean

these methods help with RSpec specs so we can ask things like:

request('/').should be_successful
request('/').should be_redirect
request('/').should be_error

Returns:

  • (Boolean)


13
14
15
# File 'lib/rackbox/rack/extensions_for_rspec.rb', line 13

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