Merge pull request #11 from ndbroadbent/master

Changed notifications at start to say "Rails starting..." instead of "Rails restarting..."
This commit is contained in:
John Bintz 2012-01-14 07:13:23 -08:00
commit 5c1e36f585
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,13 +40,33 @@ 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 '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 start and show the pid file" do
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails started/), has_entry(:image => :success))
guard.reload("start")
end
end
context 'after start' do
before do
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
context 'with pid file' do context 'with pid file' do
before do before do
runner_stub.returns(true) runner_stub.returns(true)
@ -74,6 +94,7 @@ describe Guard::Rails do
end end
end end
end end
end
describe '#stop' do describe '#stop' do
it "should stop correctly" do it "should stop correctly" do