class Shoulda::Matchers::ActionController::RespondWithMatcher

@private

Public Class Methods

new(status) click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 93
def initialize(status)
  @status = symbol_to_status_code(status)
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 110
def description
  "respond with #{@status}"
end
failure_message() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 102
def failure_message
  "Expected #{expectation}"
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 106
def failure_message_when_negated
  "Did not expect #{expectation}"
end
matches?(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 97
def matches?(controller)
  @controller = controller
  correct_status_code? || correct_status_code_range?
end

Protected Instance Methods

correct_status_code?() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 116
def correct_status_code?
  response_code == @status
end
correct_status_code_range?() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 120
def correct_status_code_range?
  @status.is_a?(Range) &&
    @status.include?(response_code)
end
expectation() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 142
def expectation
  "response to be a #{@status}, but was #{response_code}"
end
response_code() click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 125
def response_code
  @controller.response.response_code
end
symbol_to_status_code(potential_symbol) click to toggle source
# File lib/shoulda/matchers/action_controller/respond_with_matcher.rb, line 129
def symbol_to_status_code(potential_symbol)
  case potential_symbol
  when :success  then 200
  when :redirect then 300..399
  when :missing  then 404
  when :error    then 500..599
  when Symbol
    ::Rack::Utils::SYMBOL_TO_STATUS_CODE[potential_symbol]
  else
    potential_symbol
  end
end