SimpleCov Rails

Code Coverage for Rails Projects
Icons/chart bar
Used 24 times
Created by
B Ben Morrall

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/XLEsWl"
Template Source

Review the code before running this template on your machine.

gem 'simplecov', require: false, group: :test

run 'bundle install'

files = [
  'spec/spec_helper.rb',
  'test/test_helper.rb'
]

files.each do |filename|
  if File.exist?(filename)
	prepend_to_file filename, <<~TEMPLATE
unless ENV["SKIP_COVERAGE"] == "1"
  require "simplecov"
  SimpleCov.start "rails" do
    enable_coverage :branch
    minimum_coverage 100
  end
end

TEMPLATE
  end
end

append_to_file ".gitignore", <<~TEMPLATE
# Ignore coverage
/coverage
TEMPLATE

rails_command('test') if yes?("would you like to run your coverage reports?")
Comments

Sign up or Login to leave a comment.