Sha256: 58ce24f919f32861021ebac55e7d9591e8483bd3cf5c1e4bb539cea293b75eda

Contents?: true

Size: 1.19 KB

Versions: 91

Compression:

Stored size: 1.19 KB

Contents

module Shoulda # :nodoc:
  module ActionController # :nodoc:
    module Matchers

      # 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

Version data entries

91 entries across 61 versions & 10 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.7.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.7.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.7.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.7.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.7 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.6 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.5 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.3 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.2 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.1 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.6.0 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
dirty_history-0.5.4 dirty_history/ruby/1.9.1/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-2.11.3/lib/shoulda/action_controller/matchers/render_template_matcher.rb