How about spec&#39;ing links?<br><br>&lt;%= link_to &#39;Create new game&#39;, new_games_path %&gt;<br><br>&nbsp; it &quot;should have a create games link for admin&quot; do<br>&nbsp;&nbsp; template.stub!(:logged_in?).and_return(true)<br>
&nbsp;&nbsp; template.stub!(:admin?).and_return(true)<br>&nbsp;&nbsp; template.should have_tag(&#39;a&#39;,&#39;Create new game&#39;)<br>&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&nbsp; end&nbsp; <br><br>It says that it didn&#39;t show up<br><br>1)<br>
&#39;/games/index.rhtml should have a create games link for admin&#39; FAILED<br>Expected at least 1 elements, found 0.<br>&lt;false&gt; is not true.<br>./spec/views/games/index.rhtml_spec.rb:70:<br><br>Also all specs have a problem with the named route
<br>
<br>
ActionView::TemplateError in &#39;/games/index.rhtml should render a list of games for authenticated users&#39;<br>
undefined local variable or method `new_games_path&#39; for #&lt;#&lt;Class:0x32bd2a4&gt;:0x32bb5bc&gt;<br><br><br>I am I suppose to stub the named route somehow?<br>since a link_to generates an anchor tag shouldn&#39;t of my spec have passed?
<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">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">omen.king@gmail.com</a>&gt; wrote:<br>&gt; It didn&#39;t know what controller was, should it not know it what it is by<br>&gt; default or do I have to assign a controller at the top of my spec?
<br><br>Try template instead, or @controller.<br><br>The controller used in view specs is a generic controller that ships<br>w/ rspec_on_rails, not the controller that is mapped to the view.<br><br>&gt;<br>&gt;<br>&gt; On 10/1/07, Andrew WC Brown &lt;
<a href="mailto:omen.king@gmail.com">omen.king@gmail.com</a>&gt; wrote:<br>&gt; &gt; The was really helpful, thanks David!<br>&gt; &gt;<br>&gt; &gt; &quot;There is no simple answer to your question. If anyone offers you one,
<br>&gt; &gt; treat it with a grain of salt.&quot;<br>&gt; &gt;<br>&gt; &gt; The game I&#39;m specing actually has an attribute called grains_of_salt.<br>&gt; &gt; No Lie.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;
<br>&gt; &gt; On 10/1/07, David Chelimsky &lt; <a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>&gt; wrote:<br>&gt; &gt; &gt; On 10/1/07, Andrew WC Brown &lt;<a href="mailto:omen.king@gmail.com">omen.king@gmail.com
</a>&gt; wrote:<br>&gt; &gt; &gt; &gt; I&#39;m trying to spec a view but haven&#39;t done much view specing.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; This view render different partials depending on authentication of the
<br>&gt; user:<br>&gt; &gt; &gt; &gt; annon, admin, player<br>&gt; &gt; &gt; &gt; So I I&#39;ll write if conditionals in the view with the partials<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp; it &quot;should render signup propaganda for annon users trying to view
<br>&gt; games&quot;<br>&gt; &gt; &gt; &gt; do<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; @logged_in?.should eql(false)<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; response.should<br>&gt; render_template(&#39;_signup_propaganda&#39;)
<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp; end<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Now for my partial I know it&#39;ll be wrapped all in a div with a<br>&gt; &gt; &gt; &gt; class=&quot;signup_propaganda&quot;<br>&gt; &gt; &gt; &gt; Should I be testing for that instead? Can I write expectations for
<br>&gt; partials<br>&gt; &gt; &gt; &gt; similar to above?<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;When your specing views are you testing for the outputted results?<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp; it &quot;should render signup propaganda for annon users trying to view
<br>&gt; games&quot;<br>&gt; &gt; &gt; &gt; do<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render &quot;/games/index.rhtml&quot;<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@logged_in?.should eql(false)<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should have_tag(div, &quot;class=/&quot;signup_propaganda/&quot;&quot;)
<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;end<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; How should I be writing my spec?<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; There is no simple answer to your question. If anyone offers you one,<br>&gt; &gt; &gt; treat it with a grain of salt.
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Coding by example is a process. If you&#39;re doing it right, the examples<br>&gt; &gt; &gt; are going to change as you progress. So in this case, I might start<br>&gt; &gt; &gt; like this:
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; it &quot;should render signup propaganda for annon users trying to view<br>&gt; games&quot; do<br>&gt; &gt; &gt;&nbsp;&nbsp; controller.stub!(:logged_in?).and_return(false)<br>&gt; &gt; &gt;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;
<br>&gt; &gt; &gt;&nbsp;&nbsp; response.should have_tag(&#39;div.signup_propaganda&#39;)<br>&gt; &gt; &gt; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; The code to make this pass could just be:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &lt;div class=&#39;signup_propoganda&#39;/&gt;
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; At this point I&#39;d want to add an example about what a logged in user<br>&gt; &gt; &gt; sees to force the conditional:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; it &quot;should NOT render signup propaganda for logged in users trying to
<br>&gt; &gt; &gt; view games&quot; do<br>&gt; &gt; &gt;&nbsp;&nbsp; controller.stub!(:logged_in?).and_return(true)<br>&gt; &gt; &gt;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&gt; &gt; &gt;&nbsp;&nbsp; response.should_not have_tag(&#39;div.signup_propaganda&#39;
)<br>&gt; &gt; &gt; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; leading to this code:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; &lt;% if logged_in? %&gt;<br>&gt; &gt; &gt;&nbsp;&nbsp; &lt;div class=&#39;signup_propoganda&#39;/&gt;<br>&gt; &gt; &gt; &lt;% end %&gt;
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; At some point down the line I might decide to extract the div to a<br>&gt; &gt; &gt; partial. At *that* point, I should be able to do so without changing<br>&gt; &gt; &gt; the example. Once the partial has been extracted, then comes the
<br>&gt; &gt; &gt; question about what to do with the example, and the answer will depend<br>&gt; &gt; &gt; on a few things.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; If the partial is only ever used in this one template, and requires no
<br>&gt; &gt; &gt; additional setup, and the only reason I extracted it was to clean up<br>&gt; &gt; &gt; the template, I might leave things as/is.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Most of the time, however, I&#39;d change the examples to expect that the
<br>&gt; &gt; &gt; partial gets rendered. First, I&#39;d create a new example for the partial<br>&gt; &gt; &gt; itself and move anything from the old example that was specific to the<br>&gt; &gt; &gt; content inside that partial. Only after that&#39;s done and all examples
<br>&gt; &gt; &gt; are passing, I&#39;d change the original examples to look like this:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; it &quot;should render signup propaganda for annon users trying to view<br>&gt; games&quot; do<br>
&gt; &gt; &gt;&nbsp;&nbsp; controller.stub!(:logged_in?).and_return(false)<br>&gt; &gt; &gt;&nbsp;&nbsp; template.expect_render(:partial =&gt; &#39;signup_propoganda&#39;)<br>&gt; &gt; &gt;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&gt; &gt; &gt; end
<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; it &quot;should NOT render signup propaganda for logged in users trying to<br>&gt; &gt; &gt; view games&quot; do<br>&gt; &gt; &gt;&nbsp;&nbsp; controller.stub!(:logged_in?).and_return(true)<br>&gt; &gt; &gt;&nbsp;&nbsp; 
template.expect_render (:partial =&gt; &#39;signup_propoganda&#39;).never<br>&gt; &gt; &gt;&nbsp;&nbsp; render &quot;/games/index.rhtml&quot;<br>&gt; &gt; &gt; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; HTH,<br>&gt; &gt; &gt; David<br>
&gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; &gt; rspec-users mailing list<br>&gt; &gt; &gt; &gt; <a href="mailto:rspec-users@rubyforge.org">
rspec-users@rubyforge.org</a><br>&gt; &gt; &gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; _______________________________________________
<br>&gt; &gt; &gt; rspec-users mailing list<br>&gt; &gt; &gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; &gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users
</a><br>&gt; &gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; rspec-users mailing list<br>&gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org
</a><br>&gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<br>_______________________________________________<br>rspec-users mailing list<br><a href="mailto:rspec-users@rubyforge.org">
rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br><br>