# How to assert a specific layout

**URL:** <https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923>\
**Category:** Rails\
**Created:** [April 7, 2009, 1:34pm UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923 "2009-04-07T13:34:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 7, 2009, 1:34pm UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/1 "2009-04-07T13:34:20Z")

</div>

Hi.

Can any test-guru help me on this one.

How do I (in my functional test) that a specific controller/action  
uses a certain layout?

I would like to see something similar to assert\_template (for  
asserting a specific view), but for layouts.

How do you guys test use of a specific layout?

Jarl

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 7, 2009, 2:36pm UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/2 "2009-04-07T14:36:25Z")

</div>

This seems to work  
\*[http://bjhess.com/blog/2008/04/27/five-rails-tips/](http://bjhess.com/blog/2008/04/27/five-rails-tips/)

\*found by google for assert\_layout

Colin

2009/4/7 Jarl F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 7, 2009, 2:52pm UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/3 "2009-04-07T14:52:15Z")

</div>

Colin L. wrote:

> This seems to work  
> \*[http://bjhess.com/blog/2008/04/27/five-rails-tips/](http://bjhess.com/blog/2008/04/27/five-rails-tips/)
> 
> \*found by google for assert\_layout

I like this section:

> The flexibility of assert\_select:
> 
> Did you know you can use regular expressions with assert\_select? It’s pretty fun. Here’s a selector to verify a page does not include any table rows with ids of the form “day\_entry\_#”.  
> assert\_select “tr[id\*=?]”, /day\_entry\_\d+/, :count =\> 0

It’s the same as…

assert\_xhtml{ without!{ tr :id =\> /day\_entry\_\d+/ } }

I would really be interested to learn of an assert\_select which  
assert\_xhtml  
cannot do…

–  
Phlip

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 9, 2009, 5:31am UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/4 "2009-04-09T05:31:37Z")

</div>

Interested to see my blog post name-dropped here.

Philip, I assume you’re the original assert{ 2.0 } Philip, yes?

> **[O'Reilly Media - Technology and Business Training](https://www.oreilly.com)**
>
> Gain technology and business knowledge and hone your skills with learning resources created and curated by O'Reilly's experts: live online training, video, books, our platform has content from 200+ of the world's best publishers.

I actually had thought that project was in stasis. I’m the only  
person I know using assert{ 2.0 }, but I do love it. The assert{ }  
syntax along with the useful failure output is a big win.

Looks like you’re adding on to that puppy - cool. Sadly, I haven’t  
written an assert\_select for a long while, so assert\_xhtml isn’t  
solving any pain points at this time. But I’ll still happily go on  
using assert{ 2.0 } as is!

–  
Barry

> **[Barry Hess :: bjhess.com](https://bjhess.com)**
>
> Barry Hess writes about software, writing, creativity, media, and family.

> **[Time Tracking Software With Invoicing | Harvest](https://www.getharvest.com/)**
>
> Time tracking and management software with powerful easy reporting and streamlined online invoicing. Loved by 73,000 businesses. Get started for free.

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 10, 2009, 10:25am UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/5 "2009-04-10T10:25:10Z")

</div>

Jarl F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Hi.
> 
> Can any test-guru help me on this one.

Certainly there was.

Thanks for all the answers, also all the posts regarding alternatives.

I will have a look at all this.

Jarl

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [April 9, 2009, 5:41am UTC](https://www.ruby-forum.com/t/how-to-assert-a-specific-layout/164923/6 "2009-04-09T05:41:00Z")

</div>

bjhess wrote:

> Interested to see my blog post name-dropped here.
> 
> Philip, I assume you’re the original assert{ 2.0 } Philip, yes?
> 
> [O'Reilly Media - Technology and Business Training](http://www.oreillynet.com/ruby/blog/2008/02/assert2.html)
> 
> I actually had thought that project was in stasis. I’m the only  
> person I know using assert{ 2.0 }, but I do love it. The assert{ }  
> syntax along with the useful failure output is a big win.

The version for Ruby 1.9 has a better layout at fault time. (I can  
factually  
identify the freaking \n linefeeds in the {} block using Ripper! Woot!)

> Looks like you’re adding on to that puppy - cool. Sadly, I haven’t  
> written an assert\_select for a long while, so assert\_xhtml isn’t  
> solving any pain points at this time. But I’ll still happily go on  
> using assert{ 2.0 } as is!

Np. Another goal is its sub-modules take care of themselves, and you  
don’t need  
to worry about them if you don’t use them. xhtml.rb is not big enough  
for its  
own product, and after the 1.9 transition I will be free to unify all  
the  
diagnostic techniques into a seamless whole.

Folks, the point of the assert{ 2.0 } project is to make a lowly  
assertion as  
powerful as CppUnit ASSERT() was for me in Visual Studio (back in the  
days when  
MS still had a shred of relevance). When an assertion failed, it invoked  
a  
debugger breakpoint, and you would see in one window…

- the test source
- the call stack
- sometimes the code source
- all your local variable’s values.

There’s no reason any assert should not give you all that. You should  
not have  
to write extra at test time to get it - that would just slow you down!
