It didn&#39;t know what controller was, should it not know it what it is by default or do I have to assign a controller at the top of my spec?<br><br><div><span class="gmail_quote">On 10/1/07, <b class="gmail_sendername">Andrew WC Brown
</b> &lt;<a href="mailto:omen.king@gmail.com">omen.king@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The was really helpful, thanks David!
<span class="q"><br><br>&quot;There is no simple answer to your question. If anyone offers you one,<br>treat it with a grain of salt.&quot;<br><br></span>The game I&#39;m specing actually has an attribute called grains_of_salt.
<br>No Lie.<div><span class="e" id="q_1155bae7c30e3099_3"><br><br><br><div><span class="gmail_quote">On 10/1/07, <b class="gmail_sendername">David Chelimsky</b> &lt;<a href="mailto:dchelimsky@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
dchelimsky@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 10/1/07, Andrew WC Brown &lt;<a href="mailto:omen.king@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">omen.king@gmail.com</a>&gt; wrote:<br>&gt; I&#39;m trying to spec a view but haven&#39;t done much view specing.
<br>&gt;<br>&gt; This view render different partials depending on authentication of the user:
<br>&gt; annon, admin, player<br>&gt; So I I&#39;ll write if conditionals in the view with the partials<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp; it &quot;should render signup propaganda for annon users trying to view games&quot;<br>&gt; do
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; @logged_in?.should eql(false)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; response.should render_template(&#39;_signup_propaganda&#39;)<br>&gt;&nbsp;&nbsp; end<br>&gt;<br>&gt; Now for my partial I know it&#39;ll be wrapped all in a div with a
<br>&gt; class=&quot;signup_propaganda&quot;<br>&gt; Should I be testing for that instead? Can I write expectations for partials<br>&gt; similar to above?<br>&gt;<br>&gt;&nbsp;&nbsp;When your specing views are you testing for the outputted results?
<br>&gt;<br>&gt;&nbsp;&nbsp; it &quot;should render signup propaganda for annon users trying to view games&quot;<br>&gt; do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@logged_in?.should eql(false)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
response.should have_tag(div, &quot;class=/&quot;signup_propaganda/&quot;&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&gt;<br>&gt; How should I be writing my spec?<br><br>There is no simple answer to your question. If anyone offers you one,
<br>treat it with a grain of salt.<br><br>Coding by example is a process. If you&#39;re doing it right, the examples<br>are going to change as you progress. So in this case, I might start<br>like this:<br><br>it &quot;should render signup propaganda for annon users trying to view games&quot; do
<br>&nbsp;&nbsp;controller.stub!(:logged_in?).and_return(false)<br>&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>&nbsp;&nbsp;response.should have_tag(&#39;div.signup_propaganda&#39;)<br>end<br><br>The code to make this pass could just be:<br><br>

&lt;div class=&#39;signup_propoganda&#39;/&gt;<br><br>At this point I&#39;d want to add an example about what a logged in user<br>sees to force the conditional:<br><br>it &quot;should NOT render signup propaganda for logged in users trying to
<br>view games&quot; do<br>&nbsp;&nbsp;controller.stub!(:logged_in?).and_return(true)<br>&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>&nbsp;&nbsp;response.should_not have_tag(&#39;div.signup_propaganda&#39;)<br>end<br><br>leading to this code:
<br><br>&lt;% if logged_in? %&gt;<br>&nbsp;&nbsp;&lt;div class=&#39;signup_propoganda&#39;/&gt;<br>&lt;% end %&gt;<br><br>At some point down the line I might decide to extract the div to a<br>partial. At *that* point, I should be able to do so without changing
<br>the example. Once the partial has been extracted, then comes the<br>question about what to do with the example, and the answer will depend<br>on a few things.<br><br>If the partial is only ever used in this one template, and requires no
<br>additional setup, and the only reason I extracted it was to clean up<br>the template, I might leave things as/is.<br><br>Most of the time, however, I&#39;d change the examples to expect that the<br>partial gets rendered. First, I&#39;d create a new example for the partial
<br>itself and move anything from the old example that was specific to the<br>content inside that partial. Only after that&#39;s done and all examples<br>are passing, I&#39;d change the original examples to look like this:
<br><br>it &quot;should render signup propaganda for annon users trying to view games&quot; do<br>&nbsp;&nbsp;controller.stub!(:logged_in?).and_return(false)<br>&nbsp;&nbsp;template.expect_render(:partial =&gt; &#39;signup_propoganda&#39;)<br>

&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>end<br><br>it &quot;should NOT render signup propaganda for logged in users trying to<br>view games&quot; do<br>&nbsp;&nbsp;controller.stub!(:logged_in?).and_return(true)<br>&nbsp;&nbsp;template.expect_render

(:partial =&gt; &#39;signup_propoganda&#39;).never<br>&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>end<br><br>HTH,<br>David<br><br>&gt;<br>&gt; _______________________________________________<br>&gt; rspec-users mailing list
<br>&gt; <a href="mailto:rspec-users@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rspec-users@rubyforge.org</a><br>&gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<br>_______________________________________________
<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://rubyforge.org/mailman/listinfo/rspec-users</a>
<br></blockquote></div><br>
</span></div></blockquote></div>