ruby - Chefspec loads libraries repeatedly and gives the warning "already initialized constant CONSTANT" -
i have chef cookbook library, e.g. library.rb
. contains constant
:
constant = 'constant'
when write unit tests cookbook, gives me warning:
(some prefix...)warning: initialized constant constant (some prefix...)warning: previous definition of constant here
the warnings come repeatedly, many times number of examples (test cases) minus one. think because chefspec loads libraries once each example. tell me how make libraries load once, or how disable warning message?
short term, change to:
constant ||= 'constant'
long term, it's better use let()
, or move constant out of test case, or choose other way of replacing constant, or ensure testing code loads library once, not many times.
edit -- point @sawa in comments: if constant nil
or false
, ||=
approach doesn't stop warnings, you'll want better solution such as:
constant = 'constant' unless defined? constant
Comments
Post a Comment