3
votes

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?

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

2 Answers

1
votes

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.

1
votes

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.