Skip to content

Commit

Permalink
Requiring Files before Simplecov.start as mentioned by @bf4 in
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Jul 14, 2014
1 parent 7d4664e commit 1f7e434
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/minitest_helper.rb
Expand Up @@ -19,10 +19,10 @@
c.natural = true
end

require File.join(File.dirname(__FILE__), '../lib/fog/xenserver.rb')

SimpleCov.start do

This comment has been minimized.

Copy link
@bf4

bf4 Jul 14, 2014

I gather what you want here is not to get coverage info for lib/fog/xenserver?

As an aside, I recommend just using a .simplecov config file. It just works when simplecov is required.

This comment has been minimized.

Copy link
@plribeiro3000

plribeiro3000 Jul 14, 2014

Author Member

👎 for myself. Thats exactly what i don't want.

I was getting coverage info for code that was not tested like this one. That method don't have tests but is being called from another class and because of that it gives partial coverage (at least i think its because of this). What i'm missing here?

This comment has been minimized.

Copy link
@bf4

bf4 Jul 14, 2014

So, the TL;DR of SimpleCov is this

# any code that is loaded for the first time is not tracked
SimpleCov.start
# any code that is loaded for the *first time* is tracked by Ruby's Coverage module
SimpleCov.result
# any code that is loaded for the first time is not tracked

This comment has been minimized.

Copy link
@plribeiro3000

plribeiro3000 Jul 14, 2014

Author Member

So, my code should like:

SimpleCov.start
# Load my entire project
# Run all my tests
SimpleCov.result

Looking further, i found that the add_filter just tell it to not look at that files as files to be covered like config, framework stuff and the tests folder.
How do i tell Simplecov to not increase coverage based other files inside lib. In other words, how to tell it to just look for coverage from the test folder?

This comment has been minimized.

Copy link
@bf4

bf4 Jul 14, 2014

add_filter removes that pattern from the report.

I think you're misunderstanding what coverage means. coverage means executed code. When you load a Ruby file, it is evaluated, and that evaluation includes a certain amount of 'coverage'. When the test runs a method, that increases amount of code executed (if it's for the first time). If you load every single file before requiring simplecov, then run your tests, the coverage numbers will look weird because the initial evaluation of the file will not be recorded, so, you'll never get 100%, but it will only show what's actually run during the tests.

Oh, you don't need to run SimpleCov.result yourself. It's called automatically in an at_exit block.

This comment has been minimized.

Copy link
@plribeiro3000

plribeiro3000 Jul 14, 2014

Author Member

Gotcha. Thank you! I know what to do now. 😄

add_filter '/test/'
end

require File.join(File.dirname(__FILE__), '../lib/fog/xenserver.rb')

Coveralls.wear!

0 comments on commit 1f7e434

Please sign in to comment.