module MiniTest::Rails::ActionController::ControllerLookup

Public Class Methods

find(controller) click to toggle source
# File lib/minitest/rails/action_controller.rb, line 37
def self.find controller
  # HACK: I don't love this implementation
  # Please suggest a better one!
  names = controller.split "::"
  controller = while names.size > 0 do
    # Remove "Test" if present
    names.last.sub! %rTest$/, ''
    begin
      constant = names.join("::").constantize
      break(constant) if constant
    rescue NameError
      # do nothing
    ensure
      names.pop
    end
  end
  if controller.nil?
    raise ::NameError.new("Unable to resolve controller for #{name}")
  end
  controller
end