Skip to content

Commit

Permalink
SHOW_ONLY feature copied from the original rails_rcov plugin, see ht…
Browse files Browse the repository at this point in the history
…tp://svn.codahale.com/rails_rcov

Signed-off-by: commondream <alan@gnoso.com>
  • Loading branch information
dovadi authored and commondream committed Feb 17, 2009
1 parent 3e932f1 commit c92c061
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ This is a simple rails plugin that adds some useful rcov tasks.

The task ends up creating a coverage folder with an html coverage report in it.

SHOW_ONLY is a comma-separated list of the files you'd like to see (although
you can only run functionals, you still see all the models and helpers which
are 'touched'). Right now there are four types of files rake test:coverage
recognizes: models, helpers, controllers, and lib. These can be abbreviated
to their first letters:

# only show files from app/models
rake test:coverage SHOW_ONLY=models

# only show files from app/helpers and app/controllers
rake test:coverage SHOW_ONLY=helpers,controllers

# only show files from app/helpers and app/controllers, with less typing
rake test:coverage SHOW_ONLY=h,c

Requirements
============

Expand Down
23 changes: 23 additions & 0 deletions tasks/rcov.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ def run_coverage(files)
else
exclude = '--exclude "rubygems/*"'
end
# rake test:units:rcov SHOW_ONLY=models,controllers,lib,helpers
# rake test:units:rcov SHOW_ONLY=m,c,l,h
if ENV['SHOW_ONLY']
params = String.new
show_only = ENV['SHOW_ONLY'].to_s.split(',').map{|x|x.strip}
if show_only.any?
reg_exp = []
for show_type in show_only
reg_exp << case show_type
when 'm', 'models' : 'app\/models'
when 'c', 'controllers' : 'app\/controllers'
when 'h', 'helpers' : 'app\/helpers'
when 'l', 'lib' : 'lib'
else
show_type
end
end
reg_exp.map!{ |m| "(#{m})" }
params << " --exclude \"^(?!#{reg_exp.join('|')})\""
end
exclude = exclude + params
end


rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude} --no-validator-links"
puts
Expand Down

0 comments on commit c92c061

Please sign in to comment.