Rails Env Switcher allows your to switch from a rails environmemnt to another one.
Best served chilled with irb-config.
We want to run tests from the rails console.
gem 'rails-env-switcher'
If you have Pry installed, you will have access to the env
command:
pafy@bisou ~/prj/rails-prj [master●] % rails c
Loading development environment (Rails 3.2.8)
~/prj/crowdtap/rails-prj (development) > env test
~/prj/crowdtap/rails-prj (test) > Rails.env
=> "test"
~/prj/crowdtap/rails-prj (test) > exit
~/prj/crowdtap/rails-prj (development) > Rails.env
=> "development"
Programmatically:
RailsEnvSwitcher.with_env 'test', :reload => true do
# Do some stuff in the test environment
# reload => true means that we want to reload!
# Leaving the block returns in the original environment
# with_env is nestable
end
# You can also switch permantently with
RailsEnvSwitcher.switch_env 'staging'
- Middleware pattern
- Testing
MIT License