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

Getting simplecov to work with minitest's rake task #1032

Closed
zenspider opened this issue Oct 16, 2022 · 2 comments
Closed

Getting simplecov to work with minitest's rake task #1032

zenspider opened this issue Oct 16, 2022 · 2 comments

Comments

@zenspider
Copy link
Contributor

I've always hated how rake runs tests... it's SO broken. I've been running my own test task via hoe for a very long time and recentlyish ported it over to minitest (see the file here)... it runs in a different manner and as such, the recipe in the simplecov readme doesn't work...

I'm left wondering if this is related to / a variant of #1023 or not...

Here's what I've figured out so far:

with the following recipe at the top of my test:

if ENV['COV'] then
  require 'simplecov'
  SimpleCov.start
end

a manual run works fine:

%  ruby -I... -w test/test_debride.rb

but what the minitest rake task is doing does not:

% ruby -I... -w -e 'require "minitest/autorun"; require "test/test_debride.rb"' -- 

Instead, it runs the report BEFORE the tests start.

If I remove the recipe at the top of the file and manually modify the rake task command:

% ruby -I... -w -e 'require "simplecov"; SimpleCov.start; require "minitest/autorun"; require "test/test_debride.rb"' -- 

then it works again.

AFAICT... this has something to do with the way you're checking for minitest (the guess methods?) or hooking at_exit ... having the minitest/autorun inclusion might be messing it up. We can either try to figure out how to make simplecov happy no matter how tests are run (minitest/autorun before or after), or I can chalk this up to my rake task doing too much too soon and build in support for simplecov to the task itself.

What do you think?

@copiousfreetime
Copy link

copiousfreetime commented May 1, 2024

Finding this in 2024 and the following seems to be working for me now, not sure what update I did with which gem, but I had 99% test coverage and then it went to 40% without any of my code changes, just gem dependencies.

Ended up with this as my task:

  Minitest::TestTask.create(:coverage) do |t|
    t.test_prelude = 'require "simplecov"; SimpleCov.start;'
    t.libs << "spec"
    t.warning = true
    t.test_globs = "{test,spec}/**/{test_*,*_spec}.rb"
  end

Resulting rake coverage:cmd

ruby -Ilib:test:.:spec -w -e 'require "simplecov"; SimpleCov.start;; require "minitest/autorun"; require "spec/paths_spec.rb"; require "spec/timed_metric_spec.rb"; require "spec/mutex_stats_spec.rb"; require "spec/metric_spec.rb"; require "spec/value_metric_spec.rb"; require "spec/interval_spec.rb"; require "spec/stats_spec.rb"; require "spec/initialize_spec.rb"; require "spec/hitimes_spec.rb"; require "spec/timed_value_metric_spec.rb"; require "spec/version_spec.rb"' --

@zenspider
Copy link
Contributor Author

@copiousfreetime: Agreed... This is what hoe does these days w/ the test_prelude, but you might want to change yours a bit to possibly fix the test coverage numbers:

t.test_prelude = %(require "simplecov"; SimpleCov.start { add_filter %p }) % [cov_filter]

where cov_filter defaults to %w[tmp test].

I've given up on the maintainers tending to their issues so I'm closing this to get it off MY radar.

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

2 participants