2011-06-01 14:06:35 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'guard/rails'
|
|
|
|
|
|
|
|
describe Guard::Rails do
|
2011-06-01 14:13:04 +00:00
|
|
|
let(:guard) { Guard::Rails.new(watchers, options) }
|
|
|
|
let(:watchers) { [] }
|
|
|
|
let(:options) { {} }
|
2011-06-01 14:06:35 +00:00
|
|
|
|
2011-06-01 14:13:04 +00:00
|
|
|
describe '#initialize' do
|
|
|
|
it "should initialize with options" do
|
|
|
|
guard
|
2011-06-01 14:36:12 +00:00
|
|
|
|
|
|
|
guard.runner.options[:port].should == 3000
|
2011-06-01 14:13:04 +00:00
|
|
|
end
|
|
|
|
end
|
2011-06-01 14:28:32 +00:00
|
|
|
|
2011-06-03 13:18:16 +00:00
|
|
|
describe '#start' do
|
|
|
|
let(:ui_expectation) { Guard::UI.expects(:info).with(regexp_matches(/#{Guard::Rails::DEFAULT_OPTIONS[:port]}/)) }
|
|
|
|
|
|
|
|
context 'start on start' do
|
|
|
|
it "should show the right message and run startup" do
|
2011-10-17 03:33:27 +00:00
|
|
|
guard.expects(:reload).once
|
2011-06-03 13:18:16 +00:00
|
|
|
ui_expectation
|
|
|
|
guard.start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no start on start' do
|
|
|
|
let(:options) { { :start_on_start => false } }
|
|
|
|
|
|
|
|
it "should show the right message and not run startup" do
|
2011-10-17 03:33:27 +00:00
|
|
|
guard.expects(:reload).never
|
2011-06-03 13:18:16 +00:00
|
|
|
ui_expectation
|
|
|
|
guard.start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-17 03:33:27 +00:00
|
|
|
describe '#reload' do
|
2011-06-01 14:28:32 +00:00
|
|
|
let(:pid) { '12345' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
|
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
context 'at start' do
|
2011-06-01 14:28:32 +00:00
|
|
|
before do
|
2012-01-14 03:42:57 +00:00
|
|
|
Guard::UI.expects(:info).with('Starting Rails...')
|
|
|
|
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails starting/), has_entry(:image => :pending))
|
2011-06-01 14:28:32 +00:00
|
|
|
runner_stub.returns(true)
|
|
|
|
end
|
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
it "should start and show the pid file" do
|
2011-06-01 14:28:32 +00:00
|
|
|
Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
|
2012-01-14 03:42:57 +00:00
|
|
|
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails started/), has_entry(:image => :success))
|
2011-06-01 14:28:32 +00:00
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
guard.reload("start")
|
2011-06-01 14:28:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
context 'after start' do
|
2011-06-01 14:28:32 +00:00
|
|
|
before do
|
2012-01-14 03:42:57 +00:00
|
|
|
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))
|
2011-06-01 14:28:32 +00:00
|
|
|
end
|
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
context 'with pid file' do
|
|
|
|
before do
|
|
|
|
runner_stub.returns(true)
|
|
|
|
end
|
2011-06-01 14:28:32 +00:00
|
|
|
|
2012-01-14 03:42:57 +00:00
|
|
|
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
|
2011-06-01 14:28:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-10-17 03:33:27 +00:00
|
|
|
|
2011-06-03 13:18:16 +00:00
|
|
|
describe '#stop' do
|
|
|
|
it "should stop correctly" do
|
|
|
|
Guard::Notifier.expects(:notify).with('Until next time...', anything)
|
|
|
|
guard.stop
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#run_on_change' do
|
2011-10-17 03:33:27 +00:00
|
|
|
it "should reload on change" do
|
|
|
|
guard.expects(:reload).once
|
2011-06-03 13:18:16 +00:00
|
|
|
guard.run_on_change([])
|
|
|
|
end
|
|
|
|
end
|
2011-06-01 14:06:35 +00:00
|
|
|
end
|
|
|
|
|