Created
July 8, 2009 18:27
-
-
Save ryanbriones/143046 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| # coverage for modified, added or untracked files in git for a rails application | |
| require 'fileutils' | |
| require 'rubygems' | |
| require 'term/ansicolor' | |
| RCOV_OPTS = File.read(File.join(Dir.pwd, 'spec/rcov.opts')).split(/\r?\n/) | |
| SPEC_OPTS = File.read(File.join(Dir.pwd, 'spec/spec.opts')).split(/\r?\n/) | |
| GIT_STATUS = `git status` | |
| SPECS_TO_RCOV = GIT_STATUS.split("\n").collect do |line| | |
| next unless line =~ /modified|added|untracked/ | |
| file = line.split(' ').last | |
| next unless file =~ /^(?:app|lib)/ | |
| spec = "spec/#{file.sub(/^app\//, '').sub(/\.rb$/, '_spec.rb')}" | |
| unless File.exists?(File.join(Dir.pwd, spec)) | |
| STDERR.puts Term::ANSIColor.red { "Missing spec: #{File.join(Dir.pwd, spec)}" } | |
| next | |
| end | |
| spec | |
| end.compact | |
| FILES_TO_RCOV = GIT_STATUS.split("\n").collect do |line| | |
| next unless line =~ /modified|added|untracked/ | |
| file = line.split(' ').last | |
| next unless file =~ /^(?:app|lib)/ | |
| file | |
| end.compact | |
| puts | |
| 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} -- #{SPEC_OPTS.join(' ')} #{SPECS_TO_RCOV.join(' ')}") | |
| system("rcov #{RCOV_OPTS.join(' ')} --exclude 'app/*,db/*,lib/*,spec/*,config/*,vendor/*,script/*' -i '#{FILES_TO_RCOV.join(',')}' `which spec` -- #{SPEC_OPTS.join(' ')} #{SPECS_TO_RCOV.join(' ')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment