Simple cov gem missing untested files in Rails

前端 未结 3 816
时光说笑
时光说笑 2020-12-03 02:57

Using simple_cov gem in a Rails app, can we have the files that we are not testing included in the report?

  • If yes, how?

  • If no,

3条回答
  •  星月不相逢
    2020-12-03 03:09

    Eager load the whole Rails app when running tests suite with code coverage. Add Rails.application.eager_load! to spec_helper.rb.

    Simplecov slows down tests that's why I use shell environment variable to turn it on. Usually my spec_helper.rb/rails_helper.rb looks something like this:

    if ENV['COVERAGE']
      require 'simplecov'
      # some SimpleCov setup, e.g. formatters
      SimpleCov.start 'rails'
    end
    
    ENV['RAILS_ENV'] ||= 'test'
    require 'spec_helper'
    require File.expand_path('../../config/environment', __FILE__)
    require 'rspec/rails'
    
    Rails.application.eager_load! if ENV['COVERAGE']
    

提交回复
热议问题