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

Question: placing the configuration file for coverband under the `initializers` directory #540

Closed meinac closed 2 months ago

meinac commented 3 months ago

I'm currently requiring the coverband gem conditionally based on an environment variable and configuring it in an initializer file and I want to make sure this does not break any functionality of the gem. I'm asking because in the Readme, it's explicitly mentioned that the configuration file must be placed at config/coverband.rb and NOT in the initializers but there is no explanation about why, could you please guide me if I can place it under the initializers directory.

This is my gem file;

gem 'coverband', require: false

and the initializer file;

# initializers/coverband.rb

return unless ENV['ENABLE_COVERBAND']

require 'coverband'

Coverband.configure do |config|
  ...
end
danmayer commented 2 months ago

Coverband will look for the config file in config/coverband.rb because coverband has to load early and if you want to have coverage of your own initializer files I do not try to hook into the rails initialization for configuration. I would recommend conditional loading to be after the Bundler.require(*Rails.groups) in the application.rb file if you want to have it disabled in the gemfile. I do this in a number of apps...

This still will let us more eagerly load the config file than the initializers.