Patrick May wrote:
I need to write tests for some behavior that needs to check a
… do stuff
… do something else
I can do it by having this sort of thing:
MOD_RUBY = true
MOD_RUBY = false
but I don’t want to get the ruby warnings. What’s another way for me
to mock this constant?
Not sure I understand the problem, but if you’re trying to redefine a
constant in a way that won’t generate warnings, how about using modules?
module M1; K = 1; end
module M2; K = 2; end
etc., for as many times as you need to change K
include M1 # now K == 1
include M2 # now K == 2
But repeating ‘include M1’ doesn’t go back to K == 1. Ruby checks to see
if the module has already been included.
If you need to be able to change the constant more dynamically, you can
do something like:
m = Module.new