Skip to content

Commit

Permalink
Fix code coverage.
Browse files Browse the repository at this point in the history
Use `rake cov` to run it.
  • Loading branch information
mattwynne committed May 24, 2013
1 parent 083a96a commit d55a1c0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ This document is a guide for those maintaining Cucumber, and others who would li
bundle install
bundle exec rake

To get code coverage results, run `bundle exec rake cov`

## Release Process

* Bump the version number in `lib/cucumber/platform.rb`.
Expand Down
18 changes: 14 additions & 4 deletions bin/cucumber
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')

if(ENV['SIMPLECOV'] && RUBY_VERSION =~ /1\.9/)
require 'simplecov'
SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
SimpleCov.start
if ENV['SIMPLECOV']
begin
require 'simplecov'
SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
SimpleCov.start do
add_filter 'iso-8859-1_steps.rb'
command_name ENV['SIMPLECOV'] # using the env var for the name is just so that
# we use different names for the results
# from features and legacy features so they're
# merged and not overwritten.
end
rescue LoadError
warn("Unable to load simplecov")
end
end

require 'cucumber/rspec/disable_option_parser'
Expand Down
2 changes: 1 addition & 1 deletion features/lib/support/normalise_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def normalise_output(out)
out = out.gsub(/tmp\/aruba\//, '') # Fix aruba path
out = out.gsub(/^.*cucumber_process\.rb.*$\n/, '')
out = out.gsub(/^\d+m\d+\.\d+s$/, '0m0.012s') # Make duration predictable
out = out.gsub(/Coverage report generated for Cucumber Features to #{Dir.pwd}\/coverage.*\n$/, '') # Remove SimpleCov message
out = out.gsub(/Coverage report generated .+$\n/, '') # Remove SimpleCov message
end

def normalise_json(json)
Expand Down
5 changes: 5 additions & 0 deletions gem_tasks/cov.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
desc 'Run all tests and collect code coverage'
task :cov do
ENV['SIMPLECOV'] = 'features'
Rake::Task['default'].invoke
end
3 changes: 3 additions & 0 deletions legacy_features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if ENV['SIMPLECOV']
ENV['SIMPLECOV'] = 'legacy features'
end
require 'rubygems'

require 'tempfile'
Expand Down
4 changes: 4 additions & 0 deletions spec/cucumber/formatter/junit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def write_file(feature_filename, data)
@formatter = TestDoubleJunitFormatter.new(runtime, '', {})
end

after(:each) do
$stdout = STDOUT
end

describe "should be able to strip control chars from cdata" do
before(:each) do
run_defined_feature
Expand Down
9 changes: 6 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
Encoding.default_internal = 'utf-8'
end

require 'rubygems'
require 'bundler'
Bundler.setup
if ENV['SIMPLECOV']
require 'simplecov'
SimpleCov.start do
command_name 'rspec'
end
end

require 'cucumber'

Expand Down

0 comments on commit d55a1c0

Please sign in to comment.