Skip to content

Instantly share code, notes, and snippets.

@abriening
Last active January 4, 2016 21:29
Show Gist options
  • Save abriening/8681540 to your computer and use it in GitHub Desktop.
Save abriening/8681540 to your computer and use it in GitHub Desktop.
simplecov for rails
diff --git a/.gitignore b/.gitignore
index e2aa052..9a467fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,12 +5,12 @@
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
-/.bundle
+.bundle/
# Ignore the default SQLite database.
-/db/*.sqlite3
+db/*.sqlite3
# Ignore all logfiles and tempfiles.
-/log/*.log
-/tmp
-/.redcar/
\ No newline at end of file
+log/*.log
+tmp/
+coverage/
diff --git a/Gemfile b/Gemfile
index f3b99cb..a4730bd 100644
--- a/Gemfile
+++ b/Gemfile
@@ -29,3 +29,6 @@ group :test do
gem 'database_cleaner'
end
+group :coverage do
+ gem 'simplecov', require: false
+end
diff --git a/Gemfile.lock b/Gemfile.lock
index 311863e..5a16234 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -54,6 +54,7 @@ GEM
rails (>= 3.0.0)
database_cleaner (1.2.0)
diff-lcs (1.2.5)
+ docile (1.1.2)
erubis (2.7.0)
execjs (2.0.2)
factory_girl (4.3.0)
@@ -129,6 +130,11 @@ GEM
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
+ simplecov (0.8.2)
+ docile (~> 1.1.0)
+ multi_json
+ simplecov-html (~> 0.8.0)
+ simplecov-html (0.8.0)
slop (3.4.7)
sprockets (2.2.2)
hike (~> 1.2)
@@ -172,6 +178,7 @@ DEPENDENCIES
mocha
pry
rails (= 3.2.16)
+ simplecov
sqlite3
therubyracer
twitter-bootstrap-rails
diff --git a/features/support/env.rb b/features/support/env.rb
index be4056a..e0165fd 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -1,3 +1,8 @@
+unless ENV["COVERAGE"].nil?
+ require 'simplecov'
+ SimpleCov.start 'rails'
+end
+
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
diff --git a/lib/tasks/coverage.rake b/lib/tasks/coverage.rake
new file mode 100644
index 0000000..9aac6f5
--- /dev/null
+++ b/lib/tasks/coverage.rake
@@ -0,0 +1,7 @@
+task :coverage do
+ ENV["COVERAGE"] = "true"
+ `rm -r coverage`
+ at_exit do
+ `open coverage/index.html`
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 1ffcf40..bdf7df6 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,3 +1,8 @@
+unless ENV["COVERAGE"].nil?
+ require 'simplecov'
+ SimpleCov.start 'rails'
+end
+
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
rake coverage default
# or
rake coverage test cucumber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment