class Shoulda::Matchers::ActionController::RescueFromMatcher

@private

Attributes

controller[R]
exception[R]
expected_method[R]
handlers[R]

Public Class Methods

new(exception) click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 40
def initialize(exception)
  @exception = exception
  @expected_method = nil
  @controller = nil
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 56
def description
  description = "rescue from #{exception}"
  description << " with ##{expected_method}" if expected_method
  description
end
failure_message() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 62
def failure_message
  "Expected #{expectation}"
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 66
def failure_message_when_negated
  "Did not expect #{expectation}"
end
matches?(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 51
def matches?(controller)
  @controller = controller
  rescues_from_exception? && method_name_matches? && handler_exists?
end
with(method) click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 46
def with(method)
  @expected_method = method
  self
end

Protected Instance Methods

expectation() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 74
def expectation
  expectation = "#{controller} to rescue from #{exception}"

  if expected_method && !method_name_matches?
    expectation << " with ##{expected_method}"
  end

  unless handler_exists?
    expectation << " but #{controller} does not respond to"\
      " #{expected_method}"
  end
  expectation
end
handler_exists?() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 105
def handler_exists?
  if expected_method.present?
    controller.respond_to? expected_method, true
  else
    true
  end
end
method_name_matches?() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 95
def method_name_matches?
  if expected_method.present?
    handlers.any? do |handler|
      handler.last == expected_method
    end
  else
    true
  end
end
rescues_from_exception?() click to toggle source
# File lib/shoulda/matchers/action_controller/rescue_from_matcher.rb, line 88
def rescues_from_exception?
  @handlers = controller.rescue_handlers.select do |handler|
    handler.first == exception.to_s
  end
  handlers.any?
end