Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executed file missing from coverage report #107

Closed
auxbuss opened this issue Jan 25, 2012 · 6 comments
Closed

executed file missing from coverage report #107

auxbuss opened this issue Jan 25, 2012 · 6 comments
Labels

Comments

@auxbuss
Copy link

auxbuss commented Jan 25, 2012

Hi,

One test file always seems to be missing from the coverage report. I have forked https://github.com/daddz/sinatra-rspec-bundler-template here: https://github.com/auxbuss/sinatra-rspec-bundler-template to demonstrate the problem. Run rake coverage and you will see that one of the spec/*_spec.rb is missing from the report, yet it has demonstrably been executed.

@nyarly
Copy link
Contributor

nyarly commented Jan 28, 2012

I'm having a very similar problem, and having a documented solutions would be very helpful. I've confirmed that the missing files aren't being passed to the root_filter in the default configuration, either.

@nyarly
Copy link
Contributor

nyarly commented Jan 28, 2012

A little poking around made it clear that what was happening was that the files that were missed had been loaded before Simplecov started. A good test for this is to run "rspec -r simplecov spec" - if the missing files are found again, you have a load order problem.

@auxbuss
Copy link
Author

auxbuss commented Jan 28, 2012

Of course. a loading error is the most likely cause, and I spent some time looking for that; hence my providing a project that demonstrates the problem. However, I tried your rspec -r simplecov spec suggestion (see here), but the result is the same, sadly.

@colszowka
Copy link
Collaborator

That's because of the way the Ruby 1.9 Coverage library works that powers SimpleCov: Once it is required (when using simplecov this happens with the SimpleCov.start) it starts tracking all files that are required. This means: Files that have been loaded before that are not visible to Coverage and therefore not to SimpleCov.

What happens in your case is:

  • RSpec runner invokes one of your spec files (the one that eventually is missing from your report)
  • That spec file requires 'spec_helper'
  • spec_helper requires SimpleCov, which loads the Coverage lib and starts tracking all following requires

Because of this running order, simplecov cannot see the initial spec file that actually loaded simplecov via the spec_helper. What you can try to remedy this is to rspec -r spec_helper to force-load the spec_helper and therefore simplecov before your actual spec files.

@auxbuss
Copy link
Author

auxbuss commented Feb 22, 2012

Okay, that works for rspec. Thanks.

However, I also have projects using test::unit. The same technique that you suggest works, although the mechanism is a bit obscure, so I'll leave what I did here, in case anyone needs it:

desc "Run tests"
Rake::TestTask.new("units") { |t|
  t.pattern = 'test/**/*_test.rb'
  t.ruby_opts = ['-r "./test/test_helper"']
}

desc "Run all unit tests with code coverage"
task :coverage do
  sh "rm -rf coverage/*"
  ENV['COVERAGE'] = "true"
  Rake::Task["units"].execute
end

@jmthomas
Copy link

Thanks auxbuss because I ran into this exact same issue. I didn't get any results because my coverage information was finishing before ANY of my tests ran. When I added the ruby_opts line I got it to work. This is my test.rake task:

require 'rake/testtask'

Rake::TestTask.new() do |t|
  t.libs << 'test'
  t.test_files = FileList['test/**/*_test.rb']
  # Force load the test_helper to ensure SimpleCov is loaded before the test files
  t.ruby_opts = ['-r "./test/test_helper"']
end

My test_helper.rb:

require 'simplecov'
SimpleCov.start do
  add_filter '/test/'
end
require 'test/unit'

mthssdrbrg added a commit to burtcorp/ktl that referenced this issue Nov 23, 2014
I had one file that consistently was missing from the resulting HTML
report that’s generated by simplecov-html, and it turns out to be
somewhat of a loading issue, see:

	simplecov-ruby/simplecov#107
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants