Hi,<br><br>I&#39;ve been trying to find an answer for this problem in the last couple hours, but I think no discussion was about this exact same thing. So here it goes, hope someone can help.<br><br>I&#39;m trying to spec a view which 
<span style="font-style: italic;">works correctly on the browser</span>, but that generates the following error when I run &quot;rake spec:views&quot;.<br><br>ActionView::TemplateError in &#39;/survey/show should display the &quot;question 4&quot; heading correctly&#39;
<br>You have a nil object when you didn&#39;t expect it!<br>The error occurred while evaluating nil.position<br>On line #1 of app/views/survey/_question_for_candidate.rhtml<br><br>&nbsp;&nbsp;&nbsp; 1: &lt;div class=&quot;question question-&lt;%= 
question.position %&gt;&quot;&gt;<br>&nbsp;&nbsp;&nbsp; 2:&nbsp;&nbsp; &lt;p class=&quot;heading&quot;&gt;<br>&nbsp;&nbsp;&nbsp; 3:&nbsp;&nbsp;&nbsp;&nbsp; &lt;span class=&quot;number&quot;&gt;&lt;%= question.position %&gt;.&lt;/span&gt;<br>&nbsp;&nbsp;&nbsp; 4:&nbsp;&nbsp;&nbsp;&nbsp; &lt;span class=&quot;description&quot;&gt;&lt;%= 
question.description %&gt;&lt;/span&gt;<br><br>RSpec is telling me that the <span style="font-style: italic;">&quot;question&quot; object is nil</span>. I can&#39;t figure it out why.<br><br>Here&#39;s the spec that generates the error (the &quot;it&quot; block should test some tags inside the &quot;response&quot; object):
<br><br>require File.dirname(__FILE__) + &#39;/../../spec_helper&#39;<br><br>describe &#39;/survey/show&#39; do<br>&nbsp; fixtures &#39;questions&#39;, &#39;alternatives&#39;<br><br>&nbsp; before(:each) do<br>&nbsp;&nbsp;&nbsp; assigns[:configurations] = {:survey_name =&gt; &#39;Whatever&#39;}
<br>&nbsp;&nbsp;&nbsp; assigns[:questions] = Array.new<br>&nbsp;&nbsp;&nbsp; assigns[:questions][4] = questions(:faixa_etaria)<br>&nbsp;&nbsp;&nbsp; @faixa_etaria = questions(:faixa_etaria)<br>&nbsp; end <br><br>&nbsp; it &#39;should display the &quot;question 4&quot; heading correctly&#39; do
<br>&nbsp;&nbsp;&nbsp; render &#39;survey/show&#39;<br>&nbsp; end <br>end<br><br>Here&#39;s the :faixa_etaria Question fixture I&#39;m using:<br><br>faixa_etaria:<br>&nbsp; id: 1<br>&nbsp; question_type_id: 1<br>&nbsp; description: &#39;Em qual das faixas etárias abaixo você se inclui?&#39;
<br>&nbsp; position: 4<br><br>(The description value is in Portuguese).<br><br>Here&#39;s the &quot;show&quot; method inside the SurveyController:<br><br>&nbsp; def show<br>&nbsp;&nbsp;&nbsp; @configurations = {}<br>&nbsp;&nbsp;&nbsp; Configuration.find(:all).each { |c| @configurations[
c.name.to_sym] = c.value }<br>&nbsp;&nbsp;&nbsp; @questions = {}<br>&nbsp;&nbsp;&nbsp; Question.find(:all).each { |q| @questions[q.position] = q } <br>&nbsp; end <br clear="all"><br><br>Here&#39;s the piece of code inside the &quot;show.rhtml&quot; template that&#39;s calling the helper method that will cause that error:
<br><br>&lt;%= render_question(@questions[4]) %&gt;<br><br>Here&#39;s the &quot;render_question&quot; method implementation, inside the SurveyHelper class (<span style="font-style: italic;">invoking &quot;render&quot; seems to be the problem, but I don&#39;t know why
</span>):<br><br>&nbsp; def render_question(question)<br>&nbsp;&nbsp;&nbsp; render(:partial =&gt; &#39;question_for_candidate&#39;, :locals =&gt; {:question =&gt; question})<br>&nbsp; end <br><br><span style="font-style: italic;">The :locals Hash has :question as a key, and that is the variable that RSpec is complaining about inside the partial
</span>.<br><br>Finally, here&#39;s the &quot;question_for_candidate&quot; partial:<br><br>&lt;div class=&quot;question question-&lt;%= question.position %&gt;&quot;&gt;<br>&nbsp; &lt;p class=&quot;heading&quot;&gt;<br>&nbsp;&nbsp;&nbsp; &lt;span class=&quot;number&quot;&gt;&lt;%= 
question.position %&gt;.&lt;/span&gt;<br>&nbsp;&nbsp;&nbsp; &lt;span class=&quot;description&quot;&gt;&lt;%= question.description %&gt;&lt;/span&gt;<br>&nbsp; &lt;/p&gt;<br>&nbsp; &lt;% for alternative in question.alternatives -%&gt; <br>&nbsp;&nbsp;&nbsp; &lt;%= radio_button &#39;candidate&#39;, &quot;question_#{
<a href="http://question.id">question.id</a>}&quot;, <a href="http://alternative.id">alternative.id</a> %&gt;<br>&nbsp;&nbsp;&nbsp; &lt;label for=&quot;candidate_question&quot;&gt;&lt;%= alternative.description %&gt;&lt;/label&gt;<br>&nbsp;&nbsp;&nbsp; &lt;br /&gt;
<br>&nbsp; &lt;% end -%&gt; <br>&lt;/div&gt;<br><br>I&#39;m not that experienced with Rails nor RSpec, so I&#39;m totally lost about this problem.<br><br>-- <br>Caio Moritz Ronchi