I have a rspec test to validate a function which works depending on the rails version. So in my code I’m planning to use Rails::VERSION::String to get the rails version.
Before the test I tried to explicitly set the rails version like this
Rails::VERSION = "2.x.x"
But when I run the test seems like rspec cannot find the Rails variable and gives me the error
uninitialized constant Rails (NameError)
So what might be I’m missing here, thanks in advance
The best way to do this is to encapsulate the rails version check in code that you control, and then stub out the different test values you want to exercise.
For example:
Alternately, if your versioning logic is that complex, you should stub out a simple wrapper: