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
def failure_message "expected #{@expected.inspect}, got #{@actual.inspect}" end
def initialize(expected, controller)
def initialize(expected, controller) @controller = controller @expected = expected end
def matches?(response)
def matches?(response) if response.respond_to?(:rendered_file) @actual = response.rendered_file 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 negative_failure_message
def negative_failure_message "expected not to render #{@expected.inspect}, but did" 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