I didn&#39;t notice that when you create a second story you&#39;d just omit the blocks that were run in the previous scenario<br><br>This is my second scenario<br><br>&nbsp; Scenario &quot;Failed creating a new topic due to error&quot; do
<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; Given &quot;a user named&quot;, &quot;Jon&quot;<br>&nbsp;&nbsp;&nbsp; Given &quot;a forum named&quot;, &quot;General&quot;<br>&nbsp;&nbsp;&nbsp; And &quot;user logged in successfully&quot;<br><br>&nbsp;&nbsp;&nbsp; When &quot;creating a new topic titled&quot;, &quot;Nicks Mom&quot; do |title|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_via_redirect &quot;/forums/#{@forum.to_param}/topics&quot;, :topic =&gt; { :title =&gt; nil, :body =&gt; nil }<br>&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp; Then &quot;user should see&quot;, &quot;topics/new&quot; do |template|<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should render_template(template)<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; And &quot;page should show&quot;, &quot;Error&quot; do |title|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should have_text(/#{title}/)<br>&nbsp;&nbsp;&nbsp; end&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp; end<br><br>Is there a better way to test for errors or would this be the appropriate way?
<br><br><br><div><span class="gmail_quote">On 9/23/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;">
That&#39;&#39;s much more clear<br><br>I noticed you omitted<br>&nbsp;&nbsp;&nbsp; And &quot;user logged in successfully&quot; do |path|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_via_redirect &quot;/session&quot;, :login =&gt; &quot;Jon&quot;, :password =&gt; &quot;your_momma&quot;
<br>&nbsp;&nbsp;&nbsp; end<br><br>My user is required to be login so without this story the test will fail.<br>Now should this be in my story because I&#39;m not testing the if login works.<br>Anyway to share it with all my stories or should I move this line into my create_user function?
<div><span class="e" id="q_11532b7ad4c915d7_1"><br><br><div><span class="gmail_quote">On 9/23/07, <b class="gmail_sendername">Pat Maddox</b> &lt;<a href="mailto:pergesu@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
pergesu@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 9/22/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;ve written a story and I run into a snag.
<br>&gt; I&#39;ve written the create_forum method and told it to set the id to 1
<br>&gt; but when it creates the forum the id is autoincremented.<br>&gt; My forums table is empty but the id keeps incrementing the newest record on<br>&gt; creation.<br>&gt; When I run the story it comes out as something like 59 which fails my story
<br>&gt; because I&#39;m asking it to look at /forums/1<br>&gt;<br>&gt; I thought of using my named routes instead of specifying the path as a<br>&gt; string.<br>&gt; That worked up until the point when I reached:<br>&gt;
<br>&gt; When &quot;creating a new topic titled&quot;, &quot;Nicks Mom&quot; do |title|<br>&gt;&nbsp;&nbsp; post topics(@forum, ??? ), :topic =&gt; { :title =&gt; title, :body =&gt; &quot;She is<br>&gt; teh hotZ!&quot; }<br>&gt; end
<br>&gt;<br>&gt; The problem was since its a nested routed I couldn&#39;t complete the post<br>&gt; request without specifying the topic_id.<br>&gt; But since the topic hasn&#39;t been created yet their is no way (that I know of)
<br>&gt; to pass the id since I don&#39;t know what it will be.<br>&gt;<br>&gt; I would think the better practice is to state the paths as strings instead<br>&gt; of using the nested routes.<br>&gt;<br>&gt;<br>&gt;<br>&gt; require 
File.join(File.dirname(__FILE__), &quot;helper&quot;)<br>&gt;<br>&gt; Story &quot;User creates a new topic&quot;, %{<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; As a user<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; I want to create a new topic<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; So that I can dicuss Nick&#39;s Mom
<br>&gt;&nbsp;&nbsp; }, :type =&gt; RailsStory do<br>&gt;<br>&gt;&nbsp;&nbsp; Scenario &quot;Successfully create a new topic in the &#39;General&#39; forum&quot; do<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Given &quot;a user named&quot;, &quot;Jon&quot; do |login|
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @user = create_user login<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Given &quot;a forum named&quot;, &quot;General&quot; do |name|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @forum = create_forum name<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts @<a href="http://forum.id" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

forum.id
</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; And &quot;user logged in successfully and was redirect to&quot;, &quot;/&quot; do |path|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post &quot;/session/create&quot;, :login =&gt; &quot;Jon&quot;, :password =&gt; &quot;your_momma&quot;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should redirect_to(&quot;/&quot;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; And &quot;user is looking at&quot;, &quot;/forums/1&quot; do |path|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get path<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should be_success
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; When &quot;creating a new topic titled&quot;, &quot;Nicks Mom&quot; do |title|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post &quot;/forums/1/topics/1/create&quot;, :topic =&gt; { :id =&gt; 1, :title =&gt;<br>&gt; title, :body =&gt; &quot;She is teh hotZ!&quot; }
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Then &quot;user should be redirected to&quot;, &quot;/forums/1/topics/1&quot; do |path|<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get path<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; response.should be_success<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&gt;<br>&gt;&nbsp;&nbsp; end
<br>&gt;<br>&gt;&nbsp;&nbsp; Scenario &quot;Failed creating a new topic due to blank fields&quot; do; end<br>&gt;&nbsp;&nbsp; Scenario &quot;Sticky a new thread&quot; do; end<br>&gt;&nbsp;&nbsp; Scenario &quot;Annoucment as a new thread&quot; do; end
<br>
&gt; end<br>&gt;<br>&gt; def create_user(login)<br>&gt;&nbsp;&nbsp; user = User.create!(<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :login =&gt; login,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :email =&gt; &quot; <a href="mailto:your@momma.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

your@momma.com</a>&quot;,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :password =&gt; &quot;your_momma&quot;,
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :password_confirmation =&gt; &quot;your_momma&quot;,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :display_name =&gt; &quot;Jon&quot;)<br>&gt;&nbsp;&nbsp; user<br>&gt;&nbsp;&nbsp;end<br>&gt;<br>&gt; def create_forum(name)<br>&gt;&nbsp;&nbsp; forum = Forum.create!(<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :id =&gt; 1,
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :name =&gt; name,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; :description =&gt; &quot;Everything from the latest gossip to the coolest<br>&gt; youtube videos.&quot;)<br>&gt;&nbsp;&nbsp; forum<br>&gt; end<br>&gt;<br>&gt;<br>&gt; How do I stop the incrementing?
<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>You don&#39;t stop the incrementing (at least afaik).&nbsp;&nbsp;That&#39;s a db thing.<br>You&#39;d have to drop and recreate the db between runs.&nbsp;&nbsp;The good news is
<br>that the instance variables that you created are available everywhere<br>within the Scenario.<br><br>I wrote a story that is very similar to yours.&nbsp;&nbsp;I only rebuilt the<br>bits that were relevant to the test:<br><br>require 
File.join(File.dirname(__FILE__), &quot;helper&quot;)<br><br>Story &quot;User creates a new topic&quot;, %{<br>&nbsp;&nbsp;&nbsp;&nbsp;As a user<br>&nbsp;&nbsp;&nbsp;&nbsp;I want to create a new topic<br>&nbsp;&nbsp;&nbsp;&nbsp;So that I can dicuss Nick&#39;s Mom<br>&nbsp;&nbsp;}, :type =&gt; RailsStory do
<br><br>&nbsp;&nbsp;Scenario &quot;Successfully create a new topic in the &#39;General&#39; forum&quot; do<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;a user named&quot;, &quot;Jon&quot; do |login|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user = create_user login<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;&nbsp;&nbsp;Given &quot;a forum named&quot;, &quot;General&quot; do |name|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@forum = create_forum name<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;&nbsp;&nbsp;When &quot;creating a new topic titled&quot;, &quot;Nicks Mom&quot; do |title|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;post_via_redirect &quot;/forums/#{@forum.to_param}/topics&quot;, :topic =&gt;
<br>{ :title =&gt; title }<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Then &quot;user should see&quot;, &quot;topics/show&quot; do |template|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.should render_template(template)<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br><br>&nbsp;&nbsp;&nbsp;&nbsp;And &quot;page should show&quot;, &quot;Nicks Mom&quot; do |title|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.should have_text(/Title: #{title}/)<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp;end<br>end<br><br>def create_user(name)<br>&nbsp;&nbsp;user = User.create! :name =&gt; name<br>&nbsp;&nbsp;user<br>end<br><br>def create_forum(name)<br>&nbsp;&nbsp;forum = Forum.create

!
(<br>&nbsp;&nbsp;&nbsp;&nbsp;:name =&gt; name,<br>&nbsp;&nbsp;&nbsp;&nbsp;:description =&gt; &quot;Everything from the latest gossip to the coolest<br>youtube videos.&quot;)<br>&nbsp;&nbsp;forum<br>end<br><br>You can see I did a couple things differently:<br><br>* Use the forum ID in the url
<br>* Use post_via_redirect<br>* Specify the template and some text that should be shown<br><br>The first item solves the problem of the autoincrementing ID, at least<br>for the forum_id part of the URL.<br><br>Your story is actually a bit broken, imo.&nbsp;&nbsp;You POST the new topic and
<br>then GET a url.&nbsp;&nbsp;But how does the user know what that URL is?&nbsp;&nbsp;More<br>likely you&#39;re redirecting them to the right URL.&nbsp;&nbsp;You should use<br>post_via_redirect because the user makes a post and then follows the<br>redirect.
<br><br>You&#39;ll have a controller spec that specifies what the redirect url<br>should be.&nbsp;&nbsp;Brief example<br><br>it &quot;should redirect to the topic&#39;s show page&quot; do<br>&nbsp;&nbsp;do_post<br>&nbsp;&nbsp;response.should redirect_to(topic_url(@mock_topic))
<br>end<br><br>The story allows you to specify the external behavior, which is that<br>the user POSTs to a url and then gets redirected to a page showing the<br>topic.&nbsp;&nbsp;The controller spec lets you specify the internal behavior,
<br>which includes the correct redirect url.<br><br>hth<br><br>Pat<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>
</span></div></blockquote></div><br><br clear="all"><br>-- <br>Monsterbox Productions<br>putting small businesses on-line<br><br>1319 Victoria Avenue East<br>Thunder Bay, Ontario P7C 1C3<br>Canada<br><br>Andrew WC Brown<br>
web-developer and owner<br><a href="mailto:andrew@monsterboxpro.com">andrew@monsterboxpro.com</a><br>P: 807-626-9009<br>F: 807-624-2705