codecov / codecov-ruby

Ruby uploader for Codecov
https://codecov.io
MIT License
73 stars 82 forks source link

Require simplecov before defining SimpleCov namespaced class #49

Closed meganemura closed 4 years ago

meganemura commented 4 years ago

It prevents NameError: uninitialized constant SimpleCov

codecov[bot] commented 4 years ago

Codecov Report

Merging #49 into master will decrease coverage by 1.58%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #49      +/-   ##
==========================================
- Coverage   88.39%   86.81%   -1.59%     
==========================================
  Files           1        1              
  Lines         181      182       +1     
==========================================
- Hits          160      158       -2     
- Misses         21       24       +3
Impacted Files Coverage Δ
lib/codecov.rb 86.81% <100%> (-1.59%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d65a3f0...dbbcf65. Read the comment docs.

drazisil commented 4 years ago

Hi @meganemura

How is this different from the directions in the doc?

require 'simplecov'
SimpleCov.start

We have many customers using this gem, I'm finding it hard to believe it's broken.

josharrington commented 4 years ago

I can confirm that this is an issue for me as well. When running the codecov formatter, it errors out with the above.

As a workaround, I used the cobertura formatter and the bash codecov uploader. Example here https://github.com/codecov/ruby-standard-2

meganemura commented 4 years ago

@drazisil

We have many customers using this gem, I'm finding it hard to believe it's broken.

If we follow the instruction of README.md, the problem will not occur. But, current code is depending that the simplecov gem is already required implicitly before codecov gem is required.

See following reproducing examples.

Gemfile 1

# frozen_string_literal: true

source "https://rubygems.org"

gem "codecov" # <- codecov first
gem "simplecov"
~/s/g/m/t/codecov-issue $ bundle exec ruby -e "Bundler.require"
Traceback (most recent call last):
    8: from -e:1:in `<main>'
    7: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler.rb:114:in `require'
    6: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:65:in `require'
    5: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:65:in `each'
    4: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:76:in `block in require'
    3: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:76:in `each'
    2: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:81:in `block (2 levels) in require'
    1: from /Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/2.6.0/bundler/runtime.rb:81:in `require'
/Users/meganemura/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/codecov-0.1.15/lib/codecov.rb:5:in `<top (required)>': uninitialized constant SimpleCov (NameError)
Did you mean?  SimpleDelegator
~/s/g/m/t/codecov-issue $ echo $status  # $status is $? for fish
1

Gemfile 2

# frozen_string_literal: true

source "https://rubygems.org"

gem "simplecov"
gem "codecov" # <- codecov second
~/s/g/m/t/codecov-issue $ bundle exec ruby -e "Bundler.require"
~/s/g/m/t/codecov-issue $ echo $status
0
drazisil commented 4 years ago

Thank you, @meganemura for that explanation.

The updated gem was cut here https://rubygems.org/gems/codecov/versions/0.1.16