Fixed notifications at start to say "Rails starting..." and "Rails started!" instead of "restarting". I enjoy accurate messages

This commit is contained in:
Nathan Broadbent 2012-01-14 11:42:57 +08:00
parent 70d76d166d
commit 14b8402e1c
2 changed files with 43 additions and 21 deletions

View File

@ -27,18 +27,19 @@ module Guard
def start def start
server = options[:server] ? "#{options[:server]} and " : "" server = options[:server] ? "#{options[:server]} and " : ""
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment." 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 end
def reload def reload(action = "restart")
UI.info "Restarting Rails..." action_cap = action.capitalize
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending) 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 if runner.restart
UI.info "Rails restarted, pid #{runner.pid}" UI.info "Rails #{action}ed, pid #{runner.pid}"
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success) Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
else else
UI.info "Rails NOT restarted, check your log files." UI.info "Rails NOT #{action}ed, check your log files."
Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed) Notifier.notify("Rails NOT #{action}ed, check your log files.", :title => "Rails NOT #{action}ed!", :image => :failed)
end end
end end

View File

@ -40,37 +40,58 @@ describe Guard::Rails do
let(:pid) { '12345' } let(:pid) { '12345' }
before do 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) Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
end end
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) } let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
context 'with pid file' do context 'at start' do
before 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) runner_stub.returns(true)
end 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::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
end end
context 'no pid file' do context 'after start' do
before 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 end
it "should restart and show the pid file" do context 'with pid file' do
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never before do
Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/)) runner_stub.returns(true)
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed)) 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 end
end end