Simplecov Setup for Rails

Public
Add Simplecov to your Rails project (works with both Minitest and RSpec)
Icons/chart bar
Used 3 times
Created by
P Peter Szinek

Usage

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

rails app:template LOCATION="https://railsbytes.com/script/V4YsEl"
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.