From 7c6317edb80e005bdfc37dfe73a9daf921a73d47 Mon Sep 17 00:00:00 2001 From: Simon Harris Date: Tue, 8 Mar 2011 08:41:29 +1100 Subject: [PATCH] Add simplecov for coverage reports --- .gitignore | 1 + Rakefile | 2 +- hamster.gemspec | 1 + spec/spec_helper.rb | 9 +++++++++ tasks/rspec.rb | 4 ---- tasks/spec.rb | 13 +++++++++++++ 6 files changed, 25 insertions(+), 5 deletions(-) delete mode 100644 tasks/rspec.rb create mode 100644 tasks/spec.rb diff --git a/.gitignore b/.gitignore index 1d45b0a7..46061202 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ pkg/* .idea .rspec .rvmrc +coverage Gemfile.lock diff --git a/Rakefile b/Rakefile index 4416a3a4..2387e6f0 100644 --- a/Rakefile +++ b/Rakefile @@ -2,4 +2,4 @@ Dir[File.expand_path("tasks/**/*.rb")].each do |task_file| require task_file end -task :default => [ :rspec ] +task :default => [ :spec ] diff --git a/hamster.gemspec b/hamster.gemspec index aa60a251..616b4ca3 100644 --- a/hamster.gemspec +++ b/hamster.gemspec @@ -15,4 +15,5 @@ Gem::Specification.new do |s| s.require_path = "lib" s.files = Dir["lib/**/*", "spec/**/*", "tasks/**/*", "Rakefile"] + s.extra_rdoc_files s.add_development_dependency("rspec", "~> 2") + s.add_development_dependency("simplecov", "~> 0.2") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bb156667..2177959f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,14 @@ # Common spec-related code goes here +require 'simplecov' +SimpleCov.start 'rails' +SimpleCov.at_exit do + SimpleCov.result.format! + open("#{SimpleCov.coverage_dir}/covered_percent", "w") do |f| + f.puts SimpleCov.result.covered_percent.to_s + end +end + STACK_OVERFLOW_DEPTH = if RUBY_ENGINE == "ruby" def calculate_stack_overflow_depth(n) calculate_stack_overflow_depth(n + 1) diff --git a/tasks/rspec.rb b/tasks/rspec.rb deleted file mode 100644 index 183c6c91..00000000 --- a/tasks/rspec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rspec/core/rake_task' - -desc "Run specifications" -RSpec::Core::RakeTask.new(:rspec) diff --git a/tasks/spec.rb b/tasks/spec.rb new file mode 100644 index 00000000..ac5cdd02 --- /dev/null +++ b/tasks/spec.rb @@ -0,0 +1,13 @@ +require 'rspec/core/rake_task' + +desc "Run specifications" +RSpec::Core::RakeTask.new(:spec) + +# task :spec do +# covered_threshold = 100 +# covered_percent = Float(File.read("coverage/covered_percent")) +# if covered_percent < covered_threshold +# $stderr.puts "" +# raise "Insufficient unit-test coverage (#{covered_percent} < #{covered_threshold})" +# end +# end