Forum: Ruby on Rails How to assert a specific layout.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jarl F. (Guest)
on 2009-04-07 15:34
(Received via mailing list)
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
Colin L. (Guest)
on 2009-04-07 16:36
(Received via mailing list)
This seems to work
*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>
Phlip (Guest)
on 2009-04-07 16:52
(Received via mailing list)
Colin L. wrote:

> This seems to work
> *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
bjhess (Guest)
on 2009-04-09 07:31
(Received via mailing list)
Interested to see my blog post name-dropped here.

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

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.

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
http://bjhess.com
http://www.getharvest.com
Phlip (Guest)
on 2009-04-09 07:41
(Received via mailing list)
bjhess wrote:

> Interested to see my blog post name-dropped here.
>
> Philip, I assume you're the original assert{ 2.0 } Philip, yes?
>
> 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!
Jarl F. (Guest)
on 2009-04-10 12:25
(Received via mailing list)
Jarl F. <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
This topic is locked and can not be replied to.