Saturday, December 25, 2010

[Rails] Re: How to test the layout of a controller?

First off, resolving my own issue:
Apparently, you can use "assert_template" to test the layout. In my
case, I could do
-
assert_template 'static/home','layouts/application'
-
which would work.

With regard to the idea about testing behavior alone:

That makes a lot of sense. A lot. My question, however, is about how
there must be a line to draw. If you were to test that the view has
the content you want, wouldn't you HAVE to be testing implementation
to an extent, as your view contains tags like e.g. <div class='span-5'
id='main'>, and you'd be testing for e.g. a div with id 'main'? It's
just not clear to me how...

> (...) You should ideally be able
> to change
> your whole implementation and still have all your tests pass.

Could you elaborate, maybe? Also, as I'm just getting started
testing, I guess it's good to know now: Is it okay to use Shoulda and
factory_girl_rails to handle all my testing? Or is rspec / cucumber
absolutely necessary? (I don't feel like changing .... but I guess I
need to know)

On Dec 24, 8:37 pm, Marnen Laibow-Koser <li...@ruby-forum.com> wrote:
> daze wrote in post #970545:
>
> > I noticed this...
>
> >http://bjhess.com/blog/2008/04/27/five-rails-tips/
>
> > But it's outdated a bit.  What should I do?  I get a DEPRECATION
> > WARNING: response.layout has been deprecated. Use template.layout
> > instead. but after googling around I can't find a definitive solution.
>
> > It's gotta be simple...
>
> You shouldn't be testing the layout of a controller.  Instead, you
> should be testing (with Cucumber) that the view has the content you
> want.
>
> Remember: test behavior, not implementation.  You should ideally be able
> to change
> your whole implementation and still have all your tests pass.
>
> Best,
> -- 
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
>
> Sent from my iPhone
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate