danmayer / coverband

Ruby production code coverage collection and reporting (line of code usage)
https://github.com/danmayer/coverband
MIT License
2.46k stars 157 forks source link

Issue on Coverband initializer on Ruby 3.1.2 #453

Closed dynelight closed 1 year ago

dynelight commented 2 years ago

I'm not sure if this is because I need to do any new or different write up for Ruby 3, but this fails:

# config/coverband.rb
Coverband.configure do |config|
  config.store = Coverband::Adapters::RedisStore.new(
    Redis.new(
      url: ENV['REDIS_URL'],
      ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
    )
  )
end
/Users/dynelight/Projects/v/config/initializers/coverband.rb:2:in `<main>': uninitialized constant Coverband (NameError)
danmayer commented 2 years ago

Are you sure you have it in your gemfile, if you have require: false you will need to require it manually in something like application.rb or remove the require: false from your gemfile. We have this running in several Ruby 3.1.2 apps without anything like this.

danmayer commented 2 years ago

sorry for the delay @dynelight I was on vacation so it took a bit to get back to you on the issue.

dynelight commented 2 years ago

No problem. I double checked and I don't have require: false:

gem 'coverband'

... on my gemfile.

Are you initializing in a similar way as me?

danmayer commented 2 years ago

Ah... sorry, the coverband configuration file should be config/coverband.rb not config/initializers/coverband.rb This came up in another recent github issue and I will be making some changes to help avoid this issue.... move the file and you should be good.

dynelight commented 2 years ago

Oh wow... is this a Ruby 3 issue? I'm having several initializers have this same problem

danmayer commented 2 years ago

No, this shouldn't be Ruby 3 and most things use initializers, I should perhaps allow that for Coverband, but it is a bit odd in that I need to bootstrap it BEFORE most of Rails is up and running, hence the unique configuration file location.

dynelight commented 2 years ago
=> Run `bin/rails server --help` for more startup options
Exiting
/Users/dynelight/Projects/v/config/routes.rb:27:in `block in <main>': uninitialized constant Coverband (NameError)

Routes file:

  mount Coverband::Reporters::Web.new, at: '/coverage', constraints: Routing::AdminConstraint.new

On the routes file, it doesn't find it..

% cat Gemfile.lock | grep coverband
    coverband (5.2.3)
danmayer commented 2 years ago

if you have bundler setup correctly it should definitely be there before routes... you can just require 'coverband' at the top of the routes file, but something seems odd about your setup.

danmayer commented 2 years ago

since some other folk shave also had some issues with configuration, I added an install task that makes it more clear where to add the config file.

https://github.com/danmayer/coverband/issues/450