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

Shaker flyeminent at hotmail.com
Wed Sep 12 05:20:31 EDT 2007

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
class MyController
  def index
    hash = {...#data provided here}
    render :partial=>'index', :layout=>false, :locals=>{:hash=>hash}

  ......#unrelated code omitted
    var data = <%= hash %>;
    <!-- process data here -->

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.

More information about the rspec-users mailing list