From 14b8402e1ce1022b90d31ecdfa8754869f3c7289 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 14 Jan 2012 11:42:57 +0800 Subject: [PATCH 1/5] Fixed notifications at start to say "Rails starting..." and "Rails started!" instead of "restarting". I enjoy accurate messages --- lib/guard/rails.rb | 17 +++++++------ spec/lib/guard/rails_spec.rb | 47 ++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/lib/guard/rails.rb b/lib/guard/rails.rb index fdcb2f2..0b19a32 100644 --- a/lib/guard/rails.rb +++ b/lib/guard/rails.rb @@ -27,18 +27,19 @@ module Guard def start server = options[:server] ? "#{options[:server]} and " : "" UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment." - reload if options[:start_on_start] + reload("start") if options[:start_on_start] end - def reload - UI.info "Restarting Rails..." - Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending) + def reload(action = "restart") + action_cap = action.capitalize + UI.info "#{action_cap}ing Rails..." + Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]} environment...", :title => "#{action_cap}ing Rails...", :image => :pending) if runner.restart - UI.info "Rails restarted, pid #{runner.pid}" - Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success) + UI.info "Rails #{action}ed, pid #{runner.pid}" + Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success) else - UI.info "Rails NOT restarted, check your log files." - Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed) + UI.info "Rails NOT #{action}ed, check your log files." + Notifier.notify("Rails NOT #{action}ed, check your log files.", :title => "Rails NOT #{action}ed!", :image => :failed) end end diff --git a/spec/lib/guard/rails_spec.rb b/spec/lib/guard/rails_spec.rb index 6cf9257..a3abb75 100644 --- a/spec/lib/guard/rails_spec.rb +++ b/spec/lib/guard/rails_spec.rb @@ -40,37 +40,58 @@ describe Guard::Rails do let(:pid) { '12345' } before do - Guard::UI.expects(:info).with('Restarting Rails...') - Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), has_entry(:image => :pending)) Guard::RailsRunner.any_instance.stubs(:pid).returns(pid) end let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) } - context 'with pid file' do + context 'at start' do before do + Guard::UI.expects(:info).with('Starting Rails...') + Guard::Notifier.expects(:notify).with(regexp_matches(/Rails starting/), has_entry(:image => :pending)) runner_stub.returns(true) end - it "should restart and show the pid file" do + it "should start and show the pid file" do Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)) - Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success)) + Guard::Notifier.expects(:notify).with(regexp_matches(/Rails started/), has_entry(:image => :success)) - guard.reload + guard.reload("start") end end - context 'no pid file' do + context 'after start' do before do - runner_stub.returns(false) + Guard::RailsRunner.any_instance.stubs(:pid).returns(pid) + Guard::UI.expects(:info).with('Restarting Rails...') + Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), has_entry(:image => :pending)) end - it "should restart and show the pid file" do - Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never - Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/)) - Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed)) + context 'with pid file' do + before do + runner_stub.returns(true) + end - guard.reload + it "should restart and show the pid file" do + Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)) + Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success)) + + guard.reload + end + end + + context 'no pid file' do + before do + runner_stub.returns(false) + end + + it "should restart and show the pid file" do + Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never + Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/)) + Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed)) + + guard.reload + end end end end -- 2.40.1 From 5a774dca2fa32c92ce514745a79be9db6fe05bcd Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 14 Jan 2012 11:51:56 +0800 Subject: [PATCH 2/5] Bumped the default timeout to 30 seconds, so that slightly larger apps don't feel left out --- lib/guard/rails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/rails.rb b/lib/guard/rails.rb index fdcb2f2..a77ae0d 100644 --- a/lib/guard/rails.rb +++ b/lib/guard/rails.rb @@ -12,7 +12,7 @@ module Guard :environment => 'development', :start_on_start => true, :force_run => false, - :timeout => 20, + :timeout => 30, :server => nil, :debugger => false } -- 2.40.1 From 5d3ceb562694d89baf450236eb180c57800b43f9 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 16 Jan 2012 09:31:09 -0500 Subject: [PATCH 3/5] bump version --- Rakefile | 4 ++-- lib/guard/rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 7050f4f..12c226b 100644 --- a/Rakefile +++ b/Rakefile @@ -15,10 +15,10 @@ RSpec::Core::RakeTask.new(:spec) namespace :spec do desc "Run on three Rubies" task :platforms do - prefix = "rvm 1.8.7,1.9.2,ree ruby" + prefix = "rvm 1.8.7,1.9.2,ree,1.9.3 do" system %{#{prefix} bundle} system %{#{prefix} bundle exec rake spec} - exit $?.exitstatus + exit $?.exitstatus if $?.exitstatus != 0 end end diff --git a/lib/guard/rails/version.rb b/lib/guard/rails/version.rb index b16fd7a..79ee8b5 100644 --- a/lib/guard/rails/version.rb +++ b/lib/guard/rails/version.rb @@ -1,4 +1,4 @@ module GuardRails - VERSION = '0.0.4' + VERSION = '0.1.0' end -- 2.40.1 From 89e18ef84d01eb9a4ad26defd9758152a560a022 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 16 Jan 2012 09:33:13 -0500 Subject: [PATCH 4/5] fix 1.9.3 warning --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index ff56dab..9c2b8e5 100644 --- a/Gemfile +++ b/Gemfile @@ -8,11 +8,11 @@ gem 'guard' gem 'guard-rspec' require 'rbconfig' -if Config::CONFIG['target_os'] =~ /darwin/i +if RbConfig::CONFIG['target_os'] =~ /darwin/i gem 'rb-fsevent', '>= 0.3.9' gem 'growl', '~> 1.0.3' end -if Config::CONFIG['target_os'] =~ /linux/i +if RbConfig::CONFIG['target_os'] =~ /linux/i gem 'rb-inotify', '>= 0.5.1' gem 'libnotify', '~> 0.1.3' end -- 2.40.1 From 963b9e0ab257d24606f96d75d88f1081848ecda4 Mon Sep 17 00:00:00 2001 From: Darrin Holst Date: Mon, 30 Jan 2012 08:20:47 -0600 Subject: [PATCH 5/5] use SIGINT instead of KILL so the pid gets cleaned up --- lib/guard/rails/runner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guard/rails/runner.rb b/lib/guard/rails/runner.rb index dff1d80..e457b43 100644 --- a/lib/guard/rails/runner.rb +++ b/lib/guard/rails/runner.rb @@ -18,9 +18,9 @@ module Guard def stop if File.file?(pid_file) - system %{kill -KILL #{File.read(pid_file).strip}} + system %{kill -SIGINT #{File.read(pid_file).strip}} wait_for_no_pid if $?.exitstatus == 0 - FileUtils.rm pid_file + FileUtils.rm pid_file, :force => true end end -- 2.40.1