[rspec-users] A bit confused with the use of assign() to test views

ct9a anexiole at gmail.com
Wed Aug 3 04:50:27 EDT 2011

also, i have just read a little more in the rspec book.

here's an extract:

------------- extract start ---------------------
View specs expose an assign method, which we use to provide data to
the view. Modify the spec as follows:

describe "messages/show.html.erb" do
   it "displays the text attribute of the message" do
         assign(:message, double("Message", :text => "Hello world!"))
         rendered.should contain("Hello world!")

The new first line of the example creates a test double, which stubs
the text( ) method with a return value of “Hello world!” and assigns
it to an @message instance variable on the view.

------------- extract end ---------------------

If :message (in the view spec) can correspond to @message variable (in
the actual show.html.erb view), is this a Rspec convention/thing?

Sorry, Im just trying to find more resources to read up on rspec but
i'm having not much luck. Appreciate your thoughts.

Thank you .

More information about the rspec-users mailing list