Simplecov: index.html file showing full test coverage of spec files, missing some model files

Created on 11 Nov 2014  路  7Comments  路  Source: simplecov-ruby/simplecov

Top of spec_helper.rb:

require 'simplecov'
SimpleCov.start
require 'simplecov-json'
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter

---

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# require 'requests/fakeweb_helper'

Dir[Rails.root.join("spec/support/**/*.rb")].sort.each {|f| require f}
...

This is strange... In the screenshot above which is a sample of coverage/index.html, it's showing me 100% test coverage on my spec files yet it's missing a number of models.

It shows I have 100% coverage on order_spec.rb yet no mention of order.rb in there. I'm not testing my test files, that wouldn't make much sense, so I'm very confused about this output and why it's happening.

It shows certain models but not others and has 100% test coverage on all of my _spec.rb files

Any suggestions on how to remedy?

Most helpful comment

Found the issue in my case.

  1. pay special attention to this:

Note: If SimpleCov starts after your application code is already loaded (via require), it won't be able to track your files and their coverage! The SimpleCov.start must be issued before any of your application code is required!

  1. I use it in a rails app so I needed this line:
    SimpleCov.start 'rails'

All 7 comments

I imagine you closed this because you looked at the various profiles you can use? Did you see https://github.com/colszowka/simplecov/issues/340 ?

It was related to the simplecov-json gem. I took it out which fixed the issue

Did you create an issue there? Link?

I didn't. I don't have time at the moment to figure out what was wrong a do a proper report.

Something about what you saw, what you tried, and what worked is a
good enough to stub an issue imho

Got this issue. I don't use the simplecov-json gem.
This is all I have in spec/rails_helper.rb regarding simplecov:

# coverage
require 'simplecov'
SimpleCov.start

I run only model tests like this: rspec spec/models

image

Found the issue in my case.

  1. pay special attention to this:

Note: If SimpleCov starts after your application code is already loaded (via require), it won't be able to track your files and their coverage! The SimpleCov.start must be issued before any of your application code is required!

  1. I use it in a rails app so I needed this line:
    SimpleCov.start 'rails'
Was this page helpful?
0 / 5 - 0 ratings