[rspec-users] testing instance variables that are set inside views
aslak hellesoy
aslak.hellesoy at gmail.com
Wed Jul 4 03:54:22 EDT 2007
On 7/3/07, Patrick Ritchie <pritchie at videotron.ca> wrote:
>
> Hi,
>
> I think @header may not be an implementation detail in this case.
>
> If your layout looks like this:
>
> ...
> <head>
> <title><%= @header || 'Default Title' %></title>
> </head>
> ...
>
> And the view we are testing looks like this:
>
> ...
> <h1><%= @header = 'Specific Title'></h1>
> ...
>
> Then setting @header is an essential behavior for the view spec.
>
> Or am I missing something?
>
Before I can answer about how to test this with RSpec, I need to
understand what's going on in the code. Isn't the head part of the
layout evaluated before the body? If that's the case, what's the point
of assigning the @header variable in the view? It wouldn't change the
title anyway.
Aslak
> Cheers!
> Patrick
>
>
> @header is an implementation detail of your view that you shouldn't
> care about in your view spec at all. I recommend you use the have_tag
> matcher instead to verify what content gets rendered as expected.
>
> Aslak
>
> On 6/29/07, Jeremy Stephens
> <jeremy.f.stephens at vanderbilt.edu> wrote:
>
>
> Hi all,
>
> In my view specs (for Rails), how can I get at instance variables that
> are set within my view? For example, if my view looks like this:
>
> <% @header = "My Header" -%>
> <div>some content</div>
>
> How can I get to @header from within my view spec? I've tried @header
> and assigns[:header] to no avail.
>
> TIA,
> Jeremy
>
> --
> Jeremy Stephens Computer Systems Analyst I School of Medicine
> Department of Biostatistics Vanderbilt University
>
> _______________________________________________
> 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