<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;p&gt;I was working on some rspec views tests and I've noticed that partial renderization can be tricky.&lt;/p&gt; &lt;p&gt;For example, if we have an index page that renders the objects list in a partial template.&lt;/p&gt; &lt;p&gt;In my case I was testing using a 'GivingClub' list:&lt;/p&gt; 

&lt;pre&gt;&lt;span class=&quot;ident&quot;&gt;describe&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;giving_clubs&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;before&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;attribute&quot;&gt;@giving_clubs&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;mock_model&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;GivingClub&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;assigns&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:giving_clubs&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@giving_clubs&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;it&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;expect render giving clubs list&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;expect_render&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:partial&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;/giving_clubs/list&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:locals&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:giving_clubs&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@giving_clubs&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;})&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;/giving_clubs/index&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Do not forget the assigns before call template.expect_render. Locals works fine in this way.&lt;/p&gt;</body>
  <created-at type="datetime">2008-06-18T13:38:37Z</created-at>
  <id type="integer">24</id>
  <permalink>rspec-view-test-for-partial-with-locals</permalink>
  <title>RSpec view test for render :partial with :locals?</title>
  <updated-at type="datetime">2008-11-13T19:57:28Z</updated-at>
  <user-id type="integer">3</user-id>
</post>
