class Shoulda::Matchers::ActionController::RenderWithLayoutMatcher

@private

Public Class Methods

new(expected_layout) click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 66
def initialize(expected_layout)
  @expected_layout =
    if expected_layout
      expected_layout.to_s
    else
      nil
    end
  @controller = nil
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 96
def description
  description = 'render with '
  description <<
    if @expected_layout.nil?
      'a layout'
    else
      "the #{@expected_layout.inspect} layout"
    end
  description
end
failure_message() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 88
def failure_message
  "Expected #{expectation}, but #{result}"
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 92
def failure_message_when_negated
  "Did not expect #{expectation}, but #{result}"
end
in_context(context) click to toggle source

Used to provide access to layouts recorded by ActionController::TemplateAssertions in Rails 3

# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 78
def in_context(context)
  @context = context
  self
end
matches?(controller) click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 83
def matches?(controller)
  @controller = controller
  rendered_with_layout? && rendered_with_expected_layout?
end

Private Instance Methods

expectation() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 135
def expectation
  "to #{description}"
end
recorded_layouts() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 127
def recorded_layouts
  if @context
    @context.instance_variable_get('@_layouts')
  else
    {}
  end
end
rendered_layouts() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 121
def rendered_layouts
  recorded_layouts.keys.compact.map { |layout|
    layout.sub(%r{^layouts/}, '')
  }
end
rendered_with_expected_layout?() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 113
def rendered_with_expected_layout?
  if @expected_layout.nil?
    true
  else
    rendered_layouts.include?(@expected_layout)
  end
end
rendered_with_layout?() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 109
def rendered_with_layout?
  !rendered_layouts.empty?
end
result() click to toggle source
# File lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb, line 139
def result
  if rendered_with_layout?
    "rendered with #{rendered_layouts.map(&:inspect).join(', ')}"
  else
    'rendered without a layout'
  end
end