1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/lib/shoulda/matchers/action_controller/render_template_matcher.rb

55 lines
1.2 KiB
Ruby
Raw Normal View History

2010-12-15 17:34:19 -05:00
module Shoulda # :nodoc:
module Matchers
module ActionController # :nodoc:
# Ensures a controller rendered the given template.
#
# Example:
#
# it { should render_template(:show) }
def render_template(template)
RenderTemplateMatcher.new(template, self)
end
class RenderTemplateMatcher # :nodoc:
def initialize(template, context)
@template = template.to_s
@context = context
end
def matches?(controller)
@controller = controller
renders_template?
end
attr_reader :failure_message, :negative_failure_message
def description
"render template #{@template}"
end
def in_context(context)
@context = context
self
end
private
def renders_template?
begin
@context.send(:assert_template, @template)
@negative_failure_message = "Didn't expect to render #{@template}"
true
rescue Test::Unit::AssertionFailedError => error
@failure_message = error.message
false
end
end
end
end
end
end