If you’re writing test with rspec, sometime you want to CHANGE constants like
1 2 3 4 5 6 7 8 9 10 11
You can choose many ways to change constants.
First options is to use
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
The merit of this way is to change constants completely and the constant is evaluated directly.
Adding to it, this method works without any libraries.
The demerit of this way is that this is something like META programming. This may not be easy to understand for ruby beginner.
Second option is to use
stub_const defined in rspec-mocks.
1 2 3 4 5 6 7 8 9 10 11 12
The merit of this way is easy to setup and easy to understand.
Ths demerit of this way is that
stub_const depends on rspec-mocks, so if you want to use
stub_const with minitest,
you have to HACK minitest.
stub_const depends on your situation. I think if the constant is important for buisiness logic,
you should choose
remove_const. If the constant is no so important testing and using rspec, you choose
I think this discussion has no goal, but I think having many options is one of the the ways to be a HACKER.