diff --git a/CHANGES.md b/CHANGES.md index 04ea4ed..4b0cdae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,7 @@ # Changes +* Get environment from RACK_ENV by default + ## 0.2.5 * Change rb-inotify and libnotify to be development dependencies diff --git a/lib/guard/puma.rb b/lib/guard/puma.rb index 9795ad6..6132249 100644 --- a/lib/guard/puma.rb +++ b/lib/guard/puma.rb @@ -7,9 +7,14 @@ module Guard class Puma < Guard attr_reader :options, :runner + + def self.default_env + ENV.fetch('RACK_ENV', 'development') + end + DEFAULT_OPTIONS = { :port => 4000, - :environment => 'development', + :environment => default_env, :start_on_start => true, :force_run => false, :timeout => 20, diff --git a/spec/lib/guard/puma_spec.rb b/spec/lib/guard/puma_spec.rb index b3bb9d9..19befc7 100644 --- a/spec/lib/guard/puma_spec.rb +++ b/spec/lib/guard/puma_spec.rb @@ -14,6 +14,29 @@ end end + describe "#default_env" do + context "when RACK_ENV is set" do + before do + @rack_env = ENV['RACK_ENV'] + end + + it "uses the value of RACK_ENV" do + ENV['RACK_ENV'] = 'production' + Guard::Puma.default_env.should == 'production' + end + + after do + ENV['RACK_ENV'] = @rack_env + end + end + + context "when RACK_ENV is not set" do + it "defaults to development" do + Guard::Puma.default_env.should == 'development' + end + end + end + describe '#start' do context 'start on start' do