[rspec-users] Testing layouts with RSpec on Rails

Jonathan Linowes jonathan at parkerhill.com
Mon Oct 22 23:25:00 EDT 2007


Its a typo (sort of). I actually call it on response rather than  
controller, which does have the layout

   it "should use application layout" do
     do_it
     response.should use_layout("application")
   end


On Oct 22, 2007, at 8:55 PM, Steve wrote:

> On Mon, 22 Oct 2007 10:40:45 -0400, Jonathan Linowes wrote:
>
>> I'm not sure if this is what you're after but I've created this
>> custom matcher to my spec_helper.rb, then in my controller spec I can
>> say
>>
>> # custom matchers
>> #---------------------
>> class UseLayout
>>    def initialize(expected)
>>      @expected = 'layouts/' + expected
>>    end
>>    def matches?(controller)
>>      @actual = controller.layout
>>      #@actual.equal?(@expected)
>>      @actual == @expected
>>    end
>>    def failure_message
>>      return "use_layout expected #{@expected.inspect}, got #
>> {@actual.inspect}", @expected, @actual
>>    end
>>    def negeative_failure_message
>>      return "use_layout expected #{@expected.inspect} not to equal #
>> {@actual.inspect}", @expected, @actual
>>    end
>> end
>>
>> def use_layout(expected)
>>    UseLayout.new(expected)
>> end
>
> This looked promising, but when I try calling controller.layout, I get
> "undefined method 'layout'" on otherwise working controller specs. I
> didn't think ActionController exposed a layout property. If this  
> something
> you exposed yourself?
>
> Thanks,
> Steve
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list