Last active
September 11, 2017 15:56
-
-
Save aks/4b2b3266ed65998d1f4c680fc21b357e to your computer and use it in GitHub Desktop.
Show independence of Rails.env and RAILS_ENV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # | |
| def show_env(msg=nil) | |
| puts msg if msg | |
| puts "Rails.env = #{Rails.env}" | |
| puts "RAILS_ENV = #{ENV['RAILS_ENV']}" | |
| puts '' | |
| end | |
| def do_fork | |
| child_pid = fork | |
| unless child_pid | |
| show_env("after fork, in child") | |
| exit! | |
| end | |
| Process.waitpid(child_pid) | |
| end | |
| def do_thread | |
| thr = Thread.new do | |
| show_env("after thread") | |
| end | |
| thr.join | |
| end | |
| show_env("top level:") | |
| Rails.env = 'test' | |
| show_env("after setting Rails.env:") | |
| do_fork | |
| do_thread | |
| Rails.env = 'development' | |
| ENV['RAILS_ENV'] = 'test' | |
| show_env("top_level, after setting RAILS_ENV") | |
| do_fork | |
| do_thread | |
| Rails.env = 'test' | |
| ENV['RAILS_ENV'] = 'test' | |
| show_env("top_level, after setting both Rails.env and RAILS_ENV") | |
| do_fork | |
| do_thread | |
| exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ be rails runner script/tester.rb | |
| Running via Spring preloader in process 22624 | |
| top level: | |
| Rails.env = development | |
| RAILS_ENV = development | |
| after setting Rails.env: | |
| Rails.env = test | |
| RAILS_ENV = development | |
| after fork, in child | |
| Rails.env = test | |
| RAILS_ENV = development | |
| after thread | |
| Rails.env = test | |
| RAILS_ENV = development | |
| top_level, after setting RAILS_ENV | |
| Rails.env = development | |
| RAILS_ENV = test | |
| after fork, in child | |
| Rails.env = development | |
| RAILS_ENV = test | |
| after thread | |
| Rails.env = development | |
| RAILS_ENV = test | |
| top_level, after setting both Rails.env and RAILS_ENV | |
| Rails.env = test | |
| RAILS_ENV = test | |
| after fork, in child | |
| Rails.env = test | |
| RAILS_ENV = test | |
| after thread | |
| Rails.env = test | |
| RAILS_ENV = test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment