1

In my config/initializers/transaction_logger.rb I have the following code

# config/initializers/transaction_logger.rb
Transaction::Logger.logger = Transaction::Logger.new("log/transations.log")

Every time I change the code and run the tests I get:

 Failure/Error: delegate :info, :warn, :debug, :error, to: :logger

 Module::DelegationError:
   #<Class:Transaction::Logger>#error delegated to logger.error, but logger is nil: Transaction::Logger

I have to run spring stop and then re-run the test again (seems initializer's code to be executing after spring stop)

How should I set Transaction::Logger.logger to avoid this problem? Thanks

Hirurg103
  • 4,783
  • 2
  • 34
  • 50

1 Answers1

1

As spring documentation says

So to avoid this problem, don't save off references to application constants in your initialization code.

Seems this can be related to setting up class variables too

I've moved setting up Transaction::Logger.logger into Transaction::Logger file

# app/core/transaction/logger.rb
class Transaction::Logger < Logger
...
end

Transaction::Logger.logger = Transaction::Logger.new("log/transactions.log")
Hirurg103
  • 4,783
  • 2
  • 34
  • 50