I never really thought of placing subdirectories in the stories directory.<br>I guess that would be useful for separating your administrative stories for the back end of your app.<br><br>I named my stories in the following convention:
<br><br>#role#_#action#_story.rb<br><br>eg:<br>user_creates_project_story.rb<br>user_edits_project_story.rb<br>user_deletes_project_story.rb<br>user_views_project_story.rb<br><br><br><div class="gmail_quote">On Dec 21, 2007 6:40 PM, Jonathan Linowes &lt;
<a href="mailto:jonathan@parkerhill.com">jonathan@parkerhill.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I just went through this myself yesterday, and was considering
<br>posting an article on my blog, but figured it&#39;d be too short lived,<br>once the doc page is up on the rspec site. So I&#39;ll post here what<br>I&#39;ve cobbled together from various other articles, emails, and<br>
generous help on #rspec.<br><br>1. DECIDE A DIRECTORY STRUCTURE AND FILL OUT helper.rb<br>Directory structure:<br>stories/<br>stories/steps/<br>stories/stories/<br>stories/stories/foo<br>stories/stories/foo/a_foo_story<br>
stories/stories/foo/a_foo_story.rb<br>stories/stories/foo/another_foo_story<br>stories/stories/foo/another_foo_story.rb<br>stories/all.rb<br>stories/helper.rb<br><br>File: stories/helper.rb:<br><br>ENV[&quot;RAILS_ENV&quot;] = &quot;test&quot;
<br>require File.expand_path(File.dirname(__FILE__) + &quot;/../config/<br>environment&quot;)<br>require &#39;spec/rails/story_adapter&#39;<br><br>Dir[&#39;stories/steps/**/*.rb&#39;].each do |steps_file|<br> &nbsp; require steps_file
<br>end<br><br># add extra include&#39;s and helper methods here<br>include FixtureReplacement<br><br><br>2. WRITE A SHORT TEXT STORY<br><br>File: stories/stories/admin/admin_accounts<br><br>Story: admin user manages accounts
<br> &nbsp; As an admin user<br> &nbsp; I want site-wide access to accounts, projects, and users<br> &nbsp; So I can create and modify items<br><br> &nbsp; Scenario: admin user logs in<br> &nbsp; &nbsp; Given an admin user and account<br> &nbsp; &nbsp; And a bunch of accounts setup
<br> &nbsp; &nbsp; When user logs in with &nbsp;email: <a href="mailto:admin@example.com">admin@example.com</a> and password:<br>secret<br> &nbsp; &nbsp; Then browser should show the Admin page<br> &nbsp; &nbsp; And browser should show the Accounts table<br>
<br><br>3. WRITE A rb SCRIPT FOR THE STORY<br><br>File: stories/stories/admin/admin_accounts.rb<br><br>require File.join(File.dirname(__FILE__), &quot;../../helper&quot;)<br><br>with_steps_for :misc do<br> &nbsp; run File.expand_path
(__FILE__).gsub(&quot;.rb&quot;,&quot;&quot;), :type =&gt; RailsStory<br>end<br><br>For other stories, just copy this file, and add/change the steps<br>groups as required. The rest of the file is unchanged (it gets the<br>
text story filename from its own name.)<br><br><br>3.A And Run It:<br><br> &nbsp; &nbsp; &nbsp; &nbsp;$ ruby stories/stories/admin/admin_accounts.rb<br><br>should show 1 scenarios: 0 succeeded, 0 failed, 1 pending<br><br><br>4. CODE THE STEPS
<br>To start, I put all my steps into a &quot;miscellaneous&quot; steps file until<br>patterns emerge when I&#39;ll separate them out into different steps files<br><br>File: stores/steps/misc_steps.rb<br><br>steps_for(:misc) do
<br> &nbsp; Given &quot;an admin user and account&quot; do<br> &nbsp; &nbsp; @user = create_user( :email =&gt; &quot;<a href="mailto:admin@example.com">admin@example.com</a>&quot;, :password =&gt;<br>&#39;secret&#39;, :site_admin =&gt; true)
<br> &nbsp; end<br><br> &nbsp; Given &quot;a bunch of accounts setup&quot; do<br> &nbsp; &nbsp; 4.times do<br> &nbsp; &nbsp; &nbsp; create_account<br> &nbsp; &nbsp; end<br> &nbsp; end<br><br> &nbsp; When &quot;user logs in with email: $email and password: $password&quot; do |
<br>email, password|<br> &nbsp; &nbsp; post_via_redirect &quot;/sessions&quot;, :email =&gt; email, :password =&gt;<br>password, :account =&gt; account<br> &nbsp; &nbsp; response.should be_success<br> &nbsp; &nbsp; &nbsp;session[:user].should == @<a href="http://user.id" target="_blank">
user.id</a> &nbsp; &nbsp; # should_be_logged_in(@user)<br> &nbsp; end<br><br> &nbsp; Then &quot;browser should show the $h1_contents page&quot; do |h1_contents|<br> &nbsp; &nbsp; response.should have_tag(&quot;h1&quot;, h1_contents)<br> &nbsp; end<br><br> &nbsp; Then &quot;browser should show the $table_name table&quot; do |table_name|
<br> &nbsp; &nbsp; response.should have_tag(&quot;div h2&quot;, table_name)<br> &nbsp; end<br>end<br><br>4.A And Run It<br><br> &nbsp; &nbsp; &nbsp; &nbsp;$ ruby stories/stories/admin/admin_accounts.rb<br>or<br> &nbsp; &nbsp; &nbsp; &nbsp;$ ruby stories/all.rb<br><br><br><br>
<br>--linoj<br><div class="Ih2E3d"><br><br><br><br><br>On Dec 21, 2007, at 2:59 PM, Jonathan Leighton wrote:<br><br></div><div><div></div><div class="Wj3C7c">&gt; Hi all,<br>&gt;<br>&gt; Are there any plans for better documentation for the new StoryRunner
<br>&gt; feature? I tried to use it today (with Rails), and had a hard time<br>&gt; getting my head around whether I was doing it &quot;right&quot; and exactly what<br>&gt; things are appropriate to test at that level (this might be
<br>&gt; exacerbated<br>&gt; by the fact that I&#39;ve never really used integration testing that<br>&gt; much).<br>&gt; A full example of testing a Rails controller would be extremely useful<br>&gt; to me.<br>&gt;<br>&gt; Thanks,
<br>&gt;<br>&gt; Jon<br>&gt;<br>&gt; --<br>&gt; Jonathan Leighton, Web Developer<br>&gt; <a href="http://jonathanleighton.com/" target="_blank">http://jonathanleighton.com/</a><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" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users
</a><br><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" target="_blank">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br></div></div></blockquote></div><br>