6

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?

Epigene
  • 3,634
  • 1
  • 26
  • 31
  • 2
    It would be exactly the same just without the `'rails'` portion. Add this to `spec_helper.rb`. eg. (`require 'simplecov';SimpleCov.start { add_filter '/spec/'; add_group 'SomeGroup','somelib/directory';}`) – engineersmnky Jul 11 '16 at 15:03

2 Answers2

3

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.

Epigene
  • 3,634
  • 1
  • 26
  • 31
1

As engineersmnky mentioned, the code is pretty much the same regardless of the framework.

Include the SimpleCov start at the top of your spec helper before you require any files.

B Seven
  • 44,484
  • 66
  • 240
  • 385