Skip to content

Instantly share code, notes, and snippets.

@ryanbriones
Created July 8, 2009 19:32
Show Gist options
  • Select an option

  • Save ryanbriones/143118 to your computer and use it in GitHub Desktop.

Select an option

Save ryanbriones/143118 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# run coverage on a single file in rails project
require 'fileutils'
RCOV_OPTS = File.read(File.join(Dir.pwd, 'spec/rcov.opts')).split(/\r?\n/)
FILES_TO_RCOV = ARGV
SPECS_TO_RCOV = FILES_TO_RCOV.collect do |file|
spec = "spec/#{file.sub(/^app\//, '').sub(/\.rb$/, '_spec.rb')}"
unless File.exists?(File.join(Dir.pwd, spec))
STDERR.puts "Missing spec: #{File.join(Dir.pwd, spec)}"
next
end
spec
end.compact
FileUtils.rm_r(File.join(Dir.pwd, 'coverage')) if File.exists?(File.join(Dir.pwd, 'coverage'))
puts("ruby -S rcov #{RCOV_OPTS.join(' ')} --exclude 'app/*,db/*,lib/*,spec/*,config/*,vendor/*,script/*' -i '#{FILES_TO_RCOV.join(',')}' #{`which spec`.chomp} -- #{SPECS_TO_RCOV.join(' ')}")
system("rcov #{RCOV_OPTS.join(' ')} --exclude 'app/*,db/*,lib/*,spec/*,config/*,vendor/*,script/*' -i '#{FILES_TO_RCOV.join(',')}' `which spec` -- #{SPECS_TO_RCOV.join(' ')}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment