Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created January 22, 2013 23:21
Show Gist options
  • Save mipearson/4599765 to your computer and use it in GitHub Desktop.
Save mipearson/4599765 to your computer and use it in GitHub Desktop.
Assert that a set of specs actually give 100% coverage for the files they're supposed to test.
#!/usr/bin/env ruby
COVERED = %w{
app/models/ ...
}
failures = COVERED.select do |app_file|
spec_file = app_file.gsub('app', 'spec').gsub('.rb', '_spec.rb')
cmd = "sh -c 'SIMPLECOV_FOR=#{app_file} rspec #{spec_file}'"
puts "Running #{cmd}"
system cmd
$?.to_i != 0
end
if failures.length > 0
puts "The following files do not have 100% coverage or had test failures:"
puts failures.join("\n")
exit 1
end
require 'simplecov'
# Note: will NOT work with Spork in an each_run block as there is no way
# to send the environment variable to it :(
SimpleCov.start 'rails' do
if ENV['SIMPLECOV_FOR']
add_filter do |source_file|
source_file.filename != Rails.root.join(ENV['SIMPLECOV_FOR']).to_s
end
minimum_coverage 100
coverage_dir 'coverage/' + ENV['SIMPLECOV_FOR']
end
end
# .. everything else ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment