Sha256: 990be80242816cc52d18783cce7bfb0d9997686007e359a469e24b4d7de455ba

Contents?: true

Size: 1.71 KB

Versions: 28

Compression:

Stored size: 1.71 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:
        attr_reader :failure_message, :negative_failure_message

        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

        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

28 entries across 20 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/render_template_matcher.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/action_controller/render_template_matcher.rb
shoulda-matchers-1.4.2 lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb
shoulda-matchers-1.4.1 lib/shoulda/matchers/action_controller/render_template_matcher.rb
shoulda-matchers-1.4.0 lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-0.8.1 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/action_controller/render_template_matcher.rb