Sha256: 71ce8f333b1fb1508a2bb599f2960658873edd2175ad26ffef15147a44029785

Contents?: true

Size: 1.72 KB

Versions: 12

Compression:

Stored size: 1.72 KB

Contents

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

      # Ensures a controller rendered the given template.
      #
      # Example:
      #
      #   it { should render_template(:show)  }
      #
      #   assert that the "_customer" partial was rendered
      #   it { should render_template(:partial => '_customer')  }
      #
      #   assert that the "_customer" partial was rendered twice
      #   it { should render_template(:partial => '_customer', :count => 2)  }
      #
      #   assert that no partials were rendered
      #   it { should render_template(:partial => false)  }
      def render_template(options = {}, message = nil)
        RenderTemplateMatcher.new(options, message, self)
      end

      class RenderTemplateMatcher # :nodoc:

        def initialize(options, message, context)
          @options = options
          @message = message
          @template = options.is_a?(Hash) ? options[:partial] : options
          @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, @options, @message)
            @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

12 entries across 9 versions & 3 rubygems

Version Path
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/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-matchers-1.0.0/lib/shoulda/matchers/action_controller/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-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.6.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.6.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.6.0 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.5.4 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.5.3 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.5.2 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.5.1 vendor/bundle/gems/shoulda-matchers-1.0.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
shoulda-matchers-1.0.0 lib/shoulda/matchers/action_controller/render_template_matcher.rb