Sha256: 195e301fbcd0d5ad12bf585f7e222e67a95be98a17a02736369287b811aa452e

Contents?: true

Size: 1.79 KB

Versions: 53

Compression:

Stored size: 1.79 KB

Contents

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

      # Ensures that the controller rendered with the given layout.
      #
      # Example:
      #
      #   it { should render_with_layout }
      #   it { should render_with_layout(:special) }
      #   it { should_not render_with_layout }
      def render_with_layout(layout = nil)
        RenderWithLayout.new(layout)
      end

      class RenderWithLayout # :nodoc:

        def initialize(layout)
          @layout = layout.to_s unless layout.nil?
        end

        def matches?(controller)
          @controller = controller
          rendered_with_layout? && rendered_with_expected_layout?
        end

        def failure_message
          "Expected #{expectation}, but #{result}"
        end

        def negative_failure_message
          "Did not expect #{expectation}, but #{result}"
        end

        def description
          description = "render with "
          if @layout.nil?
            description << "a layout"
          else
            description << "the #{@layout.inspect} layout"
          end
          description
        end

        private

        def rendered_with_layout?
          !layout.blank?
        end

        def rendered_with_expected_layout?
          return true if @layout.nil?
          layout == @layout
        end

        def layout
          layout = @controller.response.layout
          if layout.nil?
            nil
          else
            layout.split('/').last
          end
        end

        def expectation
          "to #{description}"
        end

        def result
          if rendered_with_layout?
            "rendered with the #{layout.inspect} layout"
          else
            "rendered without a layout"
          end
        end

      end

    end
  end
end

Version data entries

53 entries across 53 versions & 15 rubygems

Version Path
fairchild-poolparty-1.3.5 vendor/gems/shoulda/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
francois-shoulda-2.10.1 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
gnip-gnip-1.1.1 test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
iGEL-shoulda-2.10.2 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
technicalpickles-shoulda-2.10.0 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
thoughtbot-shoulda-2.10.0 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
thoughtbot-shoulda-2.10.1 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
thoughtbot-shoulda-2.10.2 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
thoughtbot-shoulda-2.9.2 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
lockbox_middleware-1.2.1 vendor/gems/shoulda-2.10.2/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
robert-shoulda-2.10.4 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
robert-shoulda-2.10.3 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
simply_stated-0.0.5 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
simply_stated-0.0.4 vendor/gems/ruby/1.8/gems/shoulda-2.10.3/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
shoulda-2.10.3 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
shoulda-2.9.2 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
shoulda-2.10.0 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
shoulda-2.10.1 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
tpitale-shoulda-2.11.0 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb
shoulda-2.10.2 lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb