Sha256: dac66094cd375f2e8dbd96a470392c6935d8d665ef9016fa5ef948f29f18a150

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

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 Shoulda::Matchers::AssertionError => error
            @failure_message = error.message
            false
          end
        end

      end

    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/action_controller/render_template_matcher.rb
yetanothernguyen-shoulda-matchers-1.0.0.beta3 lib/shoulda/matchers/action_controller/render_template_matcher.rb
shoulda-matchers-1.0.0.beta2 lib/shoulda/matchers/action_controller/render_template_matcher.rb