Put Cucumber test results online quickly with Sinatra

Finding a way to make your test results readily available to those interested makes life easier for all involved. Doing this in an an always-on automated fashion is even better. For a long time I happily used Ruby on Rails to do this, but Ruby on Rails is designed for a lot more than this simple broadcast. Sinatra is a web “micro framework”, which makes it easy to do quick simple tasks, as well as build applications from the ground up without being forced to use MVC. Let’s use Sinatra to display a HTML file that has been output by a Cucumber test run.

To get Cucumber to to output results in a nicely formatted HTML page, use the following to run the test:

cucumber Blah.feature –format html –out Blah_result.html

Install sinatra with “gem install sinatra

Now in the same folder as your result file, create a file, lets call it sinatra.rb

Add the following lines:

require ‘rubygems’
require ‘sinatra’

get ‘/’ do

File.read(“Blah_result.html”)

end
On the command line run : ruby sinatra.rb
You should get :

== Sinatra/1.0 has taken the stage on 4567 for development with backup from WEBrick

Now browse to http://localhost:4567 to view your html file.
By replacing localhost with your ipaddress, anyone can view the latest test result.

Advertisement

2 Responses to Put Cucumber test results online quickly with Sinatra

  1. hey, tried running the commands in your example but kept getting unrecognised command for Blah_result.html

    I’m using rubygem cucumber 0.10.0

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 )

Connecting to %s