Mathias Stjernström
2007-Aug-29 12:35 UTC
[rspec-users] assign local variable instead of instance variable.
Hello, I have a view that generates a list of adverts with <%= render :partial => ''advert'', :collection => @adverts %> I have the render call described with @controller.template.should_receive(:render).with(:partial => ''advert'', :collection => @adverts) Bu when i was about to describe my partial i got stuck. My partial _advert.rhtml: <div id="advert_<%= advert.id %>"> <h3><%=h advert.title %></h3> <p><%=h advert.description %></p> </div> And to describe that: http://pastie.textmate.org/91995 The problem is that (assigns[:advert] = advert) creates an instance variable and :collection => @adverts creates a local variable called advert. Is there a way of assigning a local variables in a view/template from my description/spec? Cheers! Mathias Stjernstrom
Hans de Graaff
2007-Aug-29 14:32 UTC
[rspec-users] assign local variable instead of instance variable.
On Wed, 2007-08-29 at 14:35 +0200, Mathias Stjernstr?m wrote:> And to describe that: http://pastie.textmate.org/91995 > > The problem is that (assigns[:advert] = advert) creates an instance > variable and :collection => @adverts creates a local variable called > advert. > > Is there a way of assigning a local variables in a view/template from > my description/spec?I''m using "render :partial => ''some_partial'', :object => @mock_object" in those cases. Kind regards, Hans -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rspec-users/attachments/20070829/0f4ae3fa/attachment.bin
Mathias Stjernström
2007-Aug-29 20:18 UTC
[rspec-users] assign local variable instead of instance variable.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Thanks Hans, that worked like a charm!
I did however choose :locals => { :advert => @mock_object } because i
think it tells me in a much clearer way that i want to assign a local
value to the view and also the name of the variable.
I do not know if it is possible but what about an assigns_local
[:advert] => @mock_object ?
This is how it turned out: http://pastie.textmate.org/92166
Cheers!
Mathias Stjernstrom
On 29 aug 2007, at 16.32, Hans de Graaff wrote:
> On Wed, 2007-08-29 at 14:35 +0200, Mathias Stjernstr?m wrote:
>
>> And to describe that: http://pastie.textmate.org/91995
>>
>> The problem is that (assigns[:advert] = advert) creates an instance
>> variable and :collection => @adverts creates a local variable called
>> advert.
>>
>> Is there a way of assigning a local variables in a view/template from
>> my description/spec?
>
> I''m using "render :partial =>
''some_partial'', :object => @mock_object"
> in those cases.
>
> Kind regards,
>
> Hans
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iQEVAwUBRtXUnskN6DtuoU6XAQIuVAf/SUYADCa1NUAXgoxujwrhh+J7qRJDgfDr
3QoyDeEsi3M4C1FjqWblTxy6qcdO5/2hzqgB/vs8EMvsFqm9LbLxWVRIM2DQgl9j
tXVGvFTibCwb8pZnT/8QpNRwXhJQ0Yc1+G5ur1s0svtYGJevwg5Npkc9FMrDhFmI
hqO6cnYOUCPps/2D6YAf0kZxV4UMmhQa7sBCOX2QlJEh3W6uBTX0oZF5GvVyq4Y3
YSSvA/RD/e9ZPVsMwk6rsnRAHt7rrt6zndMJ65j8qAFpFTBPze5p5KAeDrbuKuyy
V8IC2vgvDCSHq1Z34kiM3TONP0tYb6Z/rtvz7F46sAU9AdFfhhEfyA==eZvA
-----END PGP SIGNATURE-----