rubyrspecsimplecov

How to integrate simplecov with a Ruby gem using RSpec (no rails)?


When adding simplecov to a rails project using RSpec, I'd place this at the very top of rails_helper.rb

require 'simplecov'

SimpleCov.start 'rails' do
  add_filter '/spec/'     

  add_group 'Controllers', 'app/controllers'
  add_group 'Models', 'app/models'
end

What is the expected location and code needed to have simplecov document the code coverage of a vanilla ruby gem?


Solution

  • Make sure you have the gem in gemspec

    s.add_development_dependency "simplecov"
    

    Then at the very top of spec/spec_helper.rb

    require 'simplecov'
    
    SimpleCov.start do
      add_filter '/spec/' 
    end
    

    This should cover the relevant /lib directory.