Short term, change it to:
CONSTANT ||= 'constant'
In the long run, it is better to use let() or transfer the constant from the test case or choose any other way to replace the constant or ensure that the test code loads the library once, and not many times.
Edit - Good point @sawa in the comments: if your constant is nil or false , then the ||= approach does not stop the warning, so you need a better solution like
CONSTANT = 'constant' unless defined? CONSTANT
source share