[rspec-users] RSpec stories introduction

Andreas Axelsson Andreas.Axelsson at combination.se
Tue Jan 15 04:00:24 EST 2008

> -----Original Message-----
> From: rspec-users-bounces at rubyforge.org [mailto:rspec-users-
> bounces at rubyforge.org] On Behalf Of James B. Byrne
> Sent: den 14 januari 2008 21:56
> To: rspec-users at rubyforge.org
> Subject: [rspec-users] RSpec stories introduction
> I have played a bit with RSpec specs and now want to check out stories.
> I
> note that there is no generator for rspec stories pre se (unless I
> managed
> to miss all references to one ) and that the only directory relating to
> stories added by installing rspec is ./stories itself.

I had a bit of trouble with this as well, and here's what I've come up with:

    │   └───vinfo

Lib contains the project, under the vinfo folder (that's the project name, substitute freely), organized like any other ruby module.
Spec contains specs, module_spec.rb, etc.
Stories contains an all.rb, which sets up the local search paths and loads all story runners from the stories\stories folder. Stories also contain a helper.rb which loads all steps and helper modules from steps and helpers.
RUBYLIB points to my lib folder above when developing.

Dir[File.join(File.dirname(__FILE__), "stories", "*.rb")].each do |file|
        require File.join(File.dirname(file), File.basename(file))

require 'rubygems'
Dir[File.dirname(__FILE__) + "/helpers/**/*.rb"].each do |file|
        require File.join(File.dirname(file), File.basename(file))
Dir[File.dirname(__FILE__) + "/steps/**/*.rb"].each do |file|
        require File.join(File.dirname(file), File.basename(file))
def runStory file
        run File.expand_path(file).gsub(".rb", ".story")

require File.join(File.dirname(__FILE__), '..', 'helper')
with_steps_for(:versiontool) do
        runStory __FILE__

Then the steps are defined just as you describe in the various steps\*.rb files with utility code in the helpers\*.rb files.

I have no idea if it's the best way to set things up, but it works for me. I've got a Rakefile in the root to run specs, stories, or all.


require 'rubygems'
require 'rcov/rcovtask'
require 'spec/rake/spectask'

task :default => [:rcov_vinfo]
task :rcov_vinfo => [:spec, :stories]

desc "Run the unit tests with rcovrt."
Spec::Rake::SpecTask.new(:spec) do |t|
        html = '../doc/vinfo_specs.html'
        t.warning = true
        t.rcov_dir = '../doc/coverage'
        t.rcov = true
        t.spec_opts = ["--color", "--format", "progress", "--format", "html:#{html}"]

desc "Run all stories"
task :stories do
        html = '../doc/vinfo_stories.html'
        ruby "stories/all.rb --color --format plain --format html:#{html}"

Hope this helps,

More information about the rspec-users mailing list