You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stubbing environment variables is a common scenario when writing specs. RSpec does not have a built-in functionality for that. As a result, there are many solutions on the internet that seem quite complicated, often requiring the installation of additional gems. However, there is a very simple solution:
moduleHelpersmoduleStubEnvHelpersdefstub_env(name,val)stub_const('ENV',ENV.to_hash.merge({name.to_s=>val}))endendendRSpec.configuredo |config|
config.includeHelpers::StubEnvHelpersend# in spec:before{stub_env(:MY_HOST,'test.localhost')}
I'm curious whether that doesn't raise any idiomatic concerns from the perspective of RSpec. Does it make sense to include it in RSpec-Core?
The text was updated successfully, but these errors were encountered:
👋 We don't include it because its relatively simple to do for a specific use case, but there are a variety of ways to do it and a variety of knock on effects; In your case you are only stubbing one extra value, but what about multiple values, or removing existing values, or etc etc. You can also just use the ENV hash as is without stubbing at all quite happily.
Lastly, closing because this is the wrong repo, rspec-core constains no stubbing at all, thats rspec-mocks.
Stubbing environment variables is a common scenario when writing specs. RSpec does not have a built-in functionality for that. As a result, there are many solutions on the internet that seem quite complicated, often requiring the installation of additional gems. However, there is a very simple solution:
I'm curious whether that doesn't raise any idiomatic concerns from the perspective of RSpec. Does it make sense to include it in RSpec-Core?
The text was updated successfully, but these errors were encountered: