Skip to content

Commit

Permalink
Added helper to help determine the layout we have for a given action.
Browse files Browse the repository at this point in the history
  • Loading branch information
baphled committed Jun 18, 2010
1 parent 30fb9b8 commit 913a167
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,38 @@ def content_for(name)
#
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
end

class UseLayout
attr_reader :expected
attr_reader :actual

def initialize(expected)
@expected = 'layouts/' + expected
end

def matches?(controller)
if controller.is_a?(ActionController::Base)
@actual = 'layouts/' + controller.class.read_inheritable_attribute(:layout)
else
@actual = controller.layout
end
@actual ||= "layouts/application"
@actual == @expected
end

def description
"Determines if a controller uses a layout"
end

def failure_message
return "use_layout expected #{@expected.inspect}, got #{@actual.inspect}"
end

def negeative_failure_message
return "use_layout expected #{@expected.inspect} not to equal #{@actual.inspect}"
end
end

def use_layout(expected)
UseLayout.new(expected)
end

0 comments on commit 913a167

Please sign in to comment.