-
Notifications
You must be signed in to change notification settings - Fork 0
Using RCov with Cucumber and Rails
This page serves as an easy way to learn how to use cucumber and RCov together.
First, Aslak recommends that you use spicycode’s RCov instead of the ‘official’ one, as it currently segfaults too much for most people’s taste.
gem sources -a http://gems.github.com gem uninstall rcov gem install spicycode-rcov
Second, you’ll need to open up the cucumber generated task file and set the rcov config option.
#lib/tasks/cucumber.rake $:.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') require 'cucumber/rake/task' Cucumber::Rake::Task.new(:features) do |t| t.cucumber_opts = "--format pretty" t.rcov = true end task :features => 'db:test:prepare'
Now when you run rake:features, coverage information will be in rails_root/coverage
See Running features
You usually want to define a task to run all your features without RCov and then have an additional task to run with RCov. Also, you usually need to specify certain options to RCov, such as output directory, for cruise control and other build purposes. Below is an example cucumer.rake file showing how to set options and define multiple cucumber tasks:
desc "Run all features"
task :features => "features:all"
task :features => 'db:test:prepare'
require 'cucumber/rake/task' #I have to add this -mischa
namespace :features do
Cucumber::Rake::Task.new(:all) do |t|
t.cucumber_opts = "--format pretty"
end
Cucumber::Rake::Task.new(:cruise) do |t|
t.cucumber_opts = "--format pretty --out=#{ENV['CC_BUILD_ARTIFACTS']}/features.txt --format html --out=#{ENV['CC_BUILD_ARTIFACTS']}/features.html"
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/}
t.rcov_opts << %[-o "#{ENV['CC_BUILD_ARTIFACTS']}/features_rcov"]
end
Cucumber::Rake::Task.new(:rcov) do |t|
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/}
t.rcov_opts << %[-o "features_rcov"]
end
end
(This was taken from bmabey’s cc.rb setup)
It is important to note that Cucumber’s default RCov options are set to %w{—rails —exclude osx\/objc,gems\/}. So you can just append to rcov_opts if those defaults work for your project.