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

no items in the coverage report #2

Closed
towerhe opened this issue Aug 26, 2010 · 4 comments
Closed

no items in the coverage report #2

towerhe opened this issue Aug 26, 2010 · 4 comments

Comments

@towerhe
Copy link

towerhe commented Aug 26, 2010

After config simplecov in my Gemfile and spec_helper.rb, i ran my specs with rake spec. i got the coverage report in my project, but there is no items in it.

Env: rails3 + ruby 1.9.2-p0

@colszowka
Copy link
Collaborator

Hi!

Is the setup of simplecov at the very first line of your spec helper? It MUST be required bevore your environment is loaded since it will only track coverage for files required after itself.

Also, Github user haobole ran into a similar issue, and told me yesterday the following:
Although I was initializing simplecov first thing in my spec_helper.rb, in my source files I was requiring other things before I required spec_helper.rb. Thanks for your help.

Please let me know if the problem persists or what exactly you had to do to fix the problem so I can update the readme!

@towerhe
Copy link
Author

towerhe commented Aug 26, 2010

it works when i setup simplecov at the head of spec_helper. thx!

@thenrio
Copy link

thenrio commented Sep 25, 2010

Hello!
Isn't this "obstrusive" ?

I explain

  • will kill rvm tests on lesser 1.8
  • will always include 'coverage' behavior

I reflect on this and spiked on top of a spec_helper
if ENV['COVERAGE'] and RUBY_VERSION =~ /1./9/
require 'simplecov'
SimpleCov.start do
add_filter '/spec/'
end
end

then
> COVERAGE=true rspec spec/
do produce coverage and
> rspec spec/
does not

Do you think of a less obstrusive integration ?

@colszowka
Copy link
Collaborator

Are you sure this fails on 1.8? Actually, there is a mechanism right at the head of the SimpleCov.start method that should just skip on coverage on Ruby 1.8. Also, for this reason the require 'coverage' happens after this check inside the start method: http://github.com/colszowka/simplecov/blob/master/lib/simplecov.rb#L31

If this doesn't work for you, please let me know, since this would indeed be a bug as the intendend behaviour on 1.8 does not work as expected.

Yes, the coverage analysis will always happen. The question to be asked here is: Why shouldn't it? Obviously, with RCov you wouldn't want this always since it slows tests down quite a bit because of the Ruby trickery it has to do to gather data. With 1.9's built-in coverage library on the other hand, coverage analysis is very fast - in my comparisons it slowed tests down less than 5%, which I think is absolutely acceptable and the benefit of always having up-to-date coverage analysis by far outweighs the performance "hit" - if you have to do additional weight-lifting to perform coverage analysis, in my experience you won't use it as much as you would when it's "just there".

Also, I think making coverage optional via an environment variable like you described it is so easy that everyone who prefers the opt-in way can achieve this without much effort without a need for a built-in mechanism in simplecov that accomplishes this. I will add this to the project Readme so people can find out how to do it easily.

Let me know what you think :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants