<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-887700532382653750</id><updated>2011-04-21T14:09:33.484-04:00</updated><category term='rspec'/><category term='stories'/><category term='BDD'/><title type='text'>Shakhruz Ashirov</title><subtitle type='html'>on web development and online business</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://shakhruz.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/887700532382653750/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://shakhruz.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shakhruz Ashirov</name><uri>http://www.blogger.com/profile/00078505106153616387</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-887700532382653750.post-3046390430371973550</id><published>2008-07-07T22:58:00.021-04:00</published><updated>2008-07-31T02:42:17.177-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rspec'/><category scheme='http://www.blogger.com/atom/ns#' term='BDD'/><category scheme='http://www.blogger.com/atom/ns#' term='stories'/><title type='text'>Quick How to start with RSpec Story Runner on Rails</title><content type='html'>Writing stories is a new awesome way to do integration testing on rails.&lt;br /&gt;If you have not read about that yet, check this out before you procede - &lt;a href="http://rspec.info/"&gt;http://rspec.info/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now let's try creating a simple story and run it with a new application.&lt;br /&gt;&lt;br /&gt;1. create a new rails application (rails 2.0.2)&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$rails storyapp&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. Install Rspec - see installation details at &lt;a href="http://github.com/dchelimsky/rspec-rails/wikis/home"&gt;http://github.com/dchelimsky/rspec-rails/wikis/home&lt;/a&gt;&lt;br /&gt;for rails 2.0.2 do the following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;cd vendor/plugins&lt;br /&gt;git clone git://github.com/dchelimsky/rspec.git&lt;br /&gt;git clone git://github.com/dchelimsky/rspec-rails.git&lt;br /&gt;cd ../../&lt;br /&gt;script/generate rspec&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You will get:&lt;br /&gt;&lt;pre&gt;$ script/generate rspec&lt;br /&gt;   create  spec&lt;br /&gt;   create  spec/spec_helper.rb&lt;br /&gt;   create  spec/spec.opts&lt;br /&gt;   create  spec/rcov.opts&lt;br /&gt;   create  script/spec_server&lt;br /&gt;   create  script/spec&lt;br /&gt;   create  lib/tasks/rspec.rake&lt;br /&gt;   create  stories&lt;br /&gt;   create  stories/all.rb&lt;br /&gt;   create  stories/helper.rb&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3. Create directory structure for your stories:&lt;br /&gt;&lt;pre&gt;$ mkdir stories/steps&lt;br /&gt;$ mkdir stories/stories&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;4. Patch your stories/helper.rb to:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="prettyprint rb-html"&gt;# stories/helper.rb&lt;br /&gt;ENV["RAILS_ENV"] = "test"&lt;br /&gt;require File.expand_path(File.dirname(__FILE__) + "/../config/environment")&lt;br /&gt;require 'spec/rails/story_adapter'&lt;br /&gt;Dir['stories/steps/**/*.rb'].each do |steps_file|&lt;br /&gt;  require steps_file&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;6. If you use Textmate install RSpec bundle for Textmate:&lt;br /&gt;&lt;a href="http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/"&gt;http://blog.emson.co.uk/2008/06/installing-the-latest-rspec-textmate-bundle/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;cd /Applications/TextMate.app/Contents/SharedSupport/Bundles&lt;br /&gt;git clone git://github.com/dchelimsky/rspec-tmbundle.git RSpec.tmbundle&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Reload your bundles in Textmate  - Bundles &gt; Bundle Editor &gt; Reload Bundles&lt;br /&gt;&lt;br /&gt;Install rspec story syntax from here - &lt;a href="http://www.movesonrails.com/articles/2007/11/06/rspec-plain-text-stories"&gt;http://www.movesonrails.com/articles/2007/11/06/rspec-plain-text-stories&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;7. Create a plain text story - stories/stories/create_course/new_course&lt;br /&gt;&lt;pre&gt;&lt;code&gt;Story: Creating a new course&lt;br /&gt;  As an admin&lt;br /&gt;  I want to create a new course&lt;br /&gt;  So that I can get subscribers and earn money&lt;br /&gt;&lt;br /&gt;  Scenario: admin is creating a new course&lt;br /&gt;    Given No courses in the system&lt;br /&gt;&lt;br /&gt;    When User creates a new course 'Test'&lt;br /&gt;    Then The course Test appears on the home page in the courses list&lt;br /&gt;    And The course Test appears in the list of courses on the admin home page&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;8. Create ruby script to run the story - stories/stories/create_course/new_course.rb&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="prettyprint rb-html"&gt;require File.join(File.dirname(__FILE__), "../../helper")&lt;br /&gt;&lt;br /&gt;with_steps_for :new_course do&lt;br /&gt;  run File.expand_path(__FILE__).gsub(".rb",""), :type =&gt; RailsStory&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;9. Run your story - $ruby stories/stories/create_course/new_course.rb&lt;br /&gt;&lt;br /&gt;You will see:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$ ruby stories/stories/create_course/new_course.rb&lt;br /&gt;Running 1 scenarios&lt;br /&gt;&lt;br /&gt;Story: Creating a new course&lt;br /&gt;&lt;br /&gt;As an admin&lt;br /&gt;I want to create a new course&lt;br /&gt;So that I can get subscribers and earn money&lt;br /&gt;&lt;br /&gt;Scenario: admin is creating a new course&lt;br /&gt;&lt;br /&gt;Given No courses in the system (PENDING)&lt;br /&gt;&lt;br /&gt;When User creates a new course 'Test' (PENDING)&lt;br /&gt;&lt;br /&gt;Then The course 'Test' appears on the home page in the courses list (PENDING)&lt;br /&gt;And The course 'Test' appears in the list of courses on the admin home page&lt;br /&gt;end&lt;br /&gt;end (PENDING)&lt;br /&gt;&lt;br /&gt;1 scenarios: 0 succeeded, 0 failed, 1 pending&lt;br /&gt;&lt;br /&gt;Pending Steps:&lt;br /&gt;1) Creating a new course (admin is creating a new course): No courses in the system&lt;br /&gt;2) Creating a new course (admin is creating a new course): User creates a new course 'Test'&lt;br /&gt;3) Creating a new course (admin is creating a new course): The course 'Test' appears on the home page in the courses list&lt;br /&gt;4) Creating a new course (admin is creating a new course): The course 'Test' appears in the list of courses on the admin home page&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;10. Create stories/steps/new_course_steps.rb&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;code class="prettyprint rb-html"&gt;steps_for(:new_course) do&lt;br /&gt;  Given "No courses in the system" do&lt;br /&gt;    Course.count(:all).should == 0&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  When "User creates a new course '$title'" do |title|&lt;br /&gt;    post_via_redirect '/courses', :name =&gt; title, :description =&gt; "Course description"&lt;br /&gt;    response.should be_success&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  Then "The course $title appears on the home page in the courses list" do |title|&lt;br /&gt;    get '/'&lt;br /&gt;    response.should have_text(title)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  Then "The course $title appears in the list of courses on the admin home page" do |title|&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;now if you run $ ruby stories/stories/create_course/new_course.rb&lt;br /&gt;or ruby stories/all.rb&lt;br /&gt;you will get:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Running 1 scenarios&lt;br /&gt;&lt;br /&gt;Story: Creating a new course&lt;br /&gt;&lt;br /&gt;As an admin&lt;br /&gt;I want to create a new course&lt;br /&gt;So that I can get subscribers and earn money&lt;br /&gt;&lt;br /&gt;Scenario: admin is creating a new course&lt;br /&gt;&lt;br /&gt;Given No courses in the system (FAILED)&lt;br /&gt;&lt;br /&gt;When User creates a new course 'Test' (SKIPPED)&lt;br /&gt;&lt;br /&gt;Then The course Test appears on the home page in the courses list (SKIPPED)&lt;br /&gt;And The course Test appears in the list of courses on the admin home page&lt;br /&gt;end&lt;br /&gt;end (PENDING)&lt;br /&gt;&lt;br /&gt;1 scenarios: 0 succeeded, 1 failed, 0 pending&lt;br /&gt;&lt;br /&gt;Pending Steps:&lt;br /&gt;1) Creating a new course (admin is creating a new course): The course Test appears in the list of courses on the admin home page&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;FAILURES:&lt;br /&gt;1) Creating a new course (admin is creating a new course) FAILED&lt;br /&gt;NameError: uninitialized constant Course&lt;br /&gt;/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:266:in `load_missing_constant'&lt;br /&gt;/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'&lt;br /&gt;/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in `const_missing'&lt;br /&gt;./stories/steps/new_course_steps.rb:3:in `No courses in the system'&lt;br /&gt;stories/all.rb:2&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;What you have now is a sample story with some steps. Of course there is no functionality there - models and controllers and your specs fail. But that's the starting point to get to writing the application  code itself. And from the story and steps we see that what we need here to make the story pass is  the Course model, course controller with create action, home page that shows courses and admin home page that also shows courses but for admin.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Happy storytelling...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Links for further reading:&lt;/div&gt;&lt;br /&gt;1. &lt;a href="http://rspec.info/"&gt;http://rspec.info/&lt;/a&gt;&lt;br /&gt;2. &lt;a href="http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/"&gt;http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/&lt;/a&gt;&lt;br /&gt;3. &lt;a href="http://www.brynary.com/bdd"&gt;http://www.brynary.com/bdd&lt;/a&gt;&lt;br /&gt;4. &lt;a href="http://www.vaporbase.com/postings/Getting_Started_with_Story_Runner"&gt;http://www.vaporbase.com/postings/Getting_Started_with_Story_Runner&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/887700532382653750-3046390430371973550?l=shakhruz.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://shakhruz.blogspot.com/feeds/3046390430371973550/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=887700532382653750&amp;postID=3046390430371973550' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/887700532382653750/posts/default/3046390430371973550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/887700532382653750/posts/default/3046390430371973550'/><link rel='alternate' type='text/html' href='http://shakhruz.blogspot.com/2008/07/quick-how-to-start-with-rspec-story.html' title='Quick How to start with RSpec Story Runner on Rails'/><author><name>Shakhruz Ashirov</name><uri>http://www.blogger.com/profile/00078505106153616387</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
