[rspec-users] Can not 'assigns' value in View test

David Chelimsky dchelimsky at gmail.com
Wed Sep 12 17:36:05 EDT 2007


On 9/12/07, Evan David Light <evan at tiggerpalace.com> wrote:
>         Granted that I'm new too; however, assigns[:hash] creates a member
> variable @hash that is made available to the view.  Maybe that's the
> problem?  Modify your view to use @hash instead.

http://rspec.rubyforge.org/documentation/rails/writing/views.html

>
> On Sep 12, 2007, at 5:20 AM, Shaker wrote:
>
> >
> > Hello everyone:
> >   I am quit new to View test using rspec. I want to write spec for a
> > partial, which is rendered by a controller. However, the controller
> > does not
> > pass data to the partial using instance variables, it uses symbol
> > variable
> > instead. I read the example of view spec provided in the website.
> > But the
> > example is using instance variable. So I am looking for a way of
> > assigning
> > my test data to the partial to be tested. I would like to show an
> > my code
> > below:
> > class MyController
> >   def index
> >     hash = {...#data provided here}
> >     render :partial=>'index', :layout=>false, :locals=>{:hash=>hash}
> >   end
> > end
> >
> > _index.rhtml
> >   ......#unrelated code omitted
> >   <script>
> >     var data = <%= hash %>;
> >     <!-- process data here -->
> >   </script>
> >
> > In my spec, I used assigns[:hash] = my_own_data, but an error
> > occurred,
> > saying that "undefined local variable or method 'hash' ".
> > How can I assign my own data to hash in my view spec?
> > Thank you!
> >
> > --
> > View this message in context: http://www.nabble.com/Can-not-%
> > 27assigns%27-value-in-View-test-tf4428018.html#a12631788
> > Sent from the rspec-users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > 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