Intergrate RSpec Story Runner into CruiseControl.rb build process with HTML report

Although still a work in progress, RSpec story runner is gaining popularity rapidly. I use it because I use Webrat for acceptance tests and Webrat integrates with the story runner seamlessly.

Then next thing I need is to create a task to integrate stories into CC.rb build process. And here it is:

desc "Run all stories"
task :all_stories do
    if out = ENV['CC_BUILD_ARTIFACTS']
        spec_out = "#{out}/Stories"
        mkdir_p spec_out unless File.directory? spec_out
        report_file_name = "#{spec_out}/index.html"
    else
        report_file_name = 'stories.html'
    end
    if ! spec_out.blank?
        sh "cp -r #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/javascripts/ #{spec_out}"
        sh "cp -r #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/stylesheets/ #{spec_out}"
    end
    sh "ruby #{RAILS_ROOT}/stories/all.rb -f html > #{report_file_name}"
end

Yes, ruby a_story.rb -f html will generate an html report instead of a plain text. That’s neat. But I also need to copy javascripts and stylesheets directories to #{spec_out} directory because the generated html report uses css and js files in these two directories.

Once you run this task as part of cruise task, you should see a Stories link under Custom Build Artifacts section. And once you click on it, you should see a page much like #{RAILS_ROOT}/vendor/plugins/rspec/story_server/prototype/stories.html.

The HTML report looks nice. But imagining when we have 100 stories all cozily live in this same single HTML file. It will take forever to load the page and it will be very difficult to find any useful information within it. My proposal is we actually generate a real index which contains just story names, and a color to indicate if they failed or not. Of course each story name is clickable which leads to another page for the detailed story report.

About these ads

~ by Yi Wen on June 25, 2008.

2 Responses to “Intergrate RSpec Story Runner into CruiseControl.rb build process with HTML report”

  1. that looks great but I’m still a little lost…
    where does this task go?
    I mean, what file and how to I get cruise control to run it?!
    Does the code go into tasks/cruise.rb for example?

  2. The code can go to lib/tasks/cruise.rake, or any of your task files. cc.rb looks for cruise task to run by default, so your cruise task can look like this:
    task :cruise => [
    'set_env_to_test',
    'db:migrate',
    'unit_spec',
    'all_stories'
    ]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: