[rspec-users] layout template

Jonathan Linowes jonathan at parkerhill.com
Tue May 29 19:13:41 EDT 2007


cool!  it works!!

I put it all in spec_helper.rb
Is there a better place to put it? your post implies the class and  
the method should be in separate files? (I dont know what is meant by  
"#included in specify blocks")
http://blog.davidchelimsky.net/articles/2007/02/18/expectation-matchers

# in spec_helper.rb

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

# in controller spec
   response.should use_layout("application")


On May 29, 2007, at 6:19 PM, David Chelimsky wrote:

> On 5/29/07, Jonathan Linowes <jonathan at parkerhill.com> wrote:
>> to answer my own question here, @layout is a variable so
>>
>>     response.layout.should == 'layouts/pages'
>
> This is a great case for a custom matcher, if you're interested.  
> Something like:
>
>    response.should use_layout('pages')
>
> Check out http://blog.davidchelimsky.net/articles/2007/02/18/custom- 
> expectation-matchers
> for info on how-to.
>
>>
>>
>>
>> On May 29, 2007, at 11:57 AM, Jonathan Linowes wrote:
>>
>>> Hi,
>>>
>>> yes I realize I can assert the view template. I'm trying to assert
>>> the layout one.
>>>
>>> I've tried
>>> response.should render_template("pages")
>>> and
>>> response.should render_template("layouts/pages")
>>> and
>>> response.should render_template("/layouts/pages")
>>> and
>>> response.should render_template('/app/views/layouts/site_pages')
>>>
>>>
>>> On May 29, 2007, at 8:36 AM, Anthony Carlos wrote:
>>>
>>>>
>>>> On May 29, 2007, at 4:54 AM, Jonathan Linowes wrote:
>>>>
>>>>> Hi, rather than flooding this list with separate emails, I've been
>>>>> queueing up questions using rspec with rails. (an irc channel  
>>>>> would
>>>>> be nice too :) Here ya go...
>>>>>
>>>>> - Can you assert which layout template is rendered in a controller
>>>>> spec?
>>>>>
>>>>
>>>> I'll answer this one:
>>>>
>>>> response.should render_template()
>>>>
>>>> Don't forget to include either a GET or POST, and if you're using
>>>> stubs or mocks, watch test.log for errors. I've noticed that when I
>>>> stub out a model object, for example, if I don't stub out all the
>>>> methods that get called before the action gets to my render,  
>>>> then the
>>>> spec fails but without a lot of related info. test.log will usually
>>>> give me a hint with a stack trace.
>>>>
>>>> It's documented here: http://rspec.rubyforge.org/documentation/ 
>>>> rails/
>>>> writing/controllers.html
>>>>
>>>>>
>>>>> That's it for now :) thanks
>>>>> linoj
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> rspec-users mailing list
>>>>> rspec-users at rubyforge.org
>>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>>
>>>> _______________________________________________
>>>> rspec-users mailing list
>>>> rspec-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>>
>>> _______________________________________________
>>> rspec-users mailing list
>>> rspec-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list