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

Gordon Yeong anexiole at gmail.com
Wed Aug 3 07:10:16 EDT 2011


Hello David
Thanks for that. Doesn't assign have 2 arguments with the first being the
variable to be assigned to and the second being the contents?
 On Aug 3, 2011 7:01 PM, "ct9a" <anexiole at gmail.com> wrote:
> also, i have just read a little more in the rspec book.
>
> here's an extract:
>
> ------------- extract start ---------------------
> assign()
> 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!"))
> render
> rendered.should contain("Hello world!")
> end
> end
>
>
> 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 .
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> --
> You received this message because you are subscribed to the Google Groups
"rspec" group.
> To post to this group, send email to rspec at googlegroups.com.
> To unsubscribe from this group, send email to
rspec+unsubscribe at googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rspec?hl=en.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110803/31c6dc4a/attachment.html>


More information about the rspec-users mailing list