class Spec::Rails::Matchers::RenderTemplate

:nodoc:

def controller_path_from(path)

def controller_path_from(path)
  parts = path.split('/')
  parts.pop
  parts.join('/')
end

def current_controller_path

def current_controller_path
  @controller.class.to_s.underscore.gsub(/_controller$/,'')
end

def description

def description
  "render template #{@expected.inspect}"
end

def failure_message_for_should

def failure_message_for_should
  "expected #{@expected.inspect}, got #{@actual.inspect}"
end

def failure_message_for_should_not

def failure_message_for_should_not
  "expected not to render #{@expected.inspect}, but did"
end

def initialize(expected, controller)

def initialize(expected, controller)
  @controller = controller
  @expected = expected
end

def matches?(response_or_controller)

def matches?(response_or_controller)
  response  = response_or_controller.respond_to?(:response) ?
              response_or_controller.response :
              response_or_controller
  if response.respond_to?(:rendered_file)
    @actual = response.rendered_file
  elsif response.respond_to?(:rendered)
    case template = response.rendered[:template]
    when nil
      unless response.rendered[:partials].empty?
        @actual = path_and_file(response.rendered[:partials].keys.first).join("/_")
      end
    when ActionView::Template
      @actual = template.path
    when String
      @actual = template
    end
  else
    @actual = response.rendered_template.to_s
  end
  return false if @actual.blank?
  given_controller_path, given_file = path_and_file(@actual)
  expected_controller_path, expected_file = path_and_file(@expected)
  given_controller_path == expected_controller_path && given_file.match(expected_file)
end

def path_and_file(path)

def path_and_file(path)
  parts = path.split('/')
  file = parts.pop
  controller = parts.empty? ? current_controller_path : parts.join('/')
  return controller, file
end