more better tests
This commit is contained in:
parent
bf2eaf9f58
commit
99d8f28d8c
1
Gemfile
1
Gemfile
|
@ -4,3 +4,4 @@ source "http://rubygems.org"
|
|||
gemspec
|
||||
gem 'rake', '0.8.7'
|
||||
gem 'growl'
|
||||
gem 'fakefs', :require => nil
|
||||
|
|
|
@ -25,11 +25,15 @@ module Guard
|
|||
end
|
||||
|
||||
def run_all
|
||||
UI.info "Restarting Rails"
|
||||
UI.info "Restarting Rails..."
|
||||
Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Rails...", :image => :pending)
|
||||
runner.restart
|
||||
UI.info "Rails restarted, pid #{File.read(pid_file)}"
|
||||
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
|
||||
if runner.restart
|
||||
UI.info "Rails restarted, pid #{runner.pid}"
|
||||
Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :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 => :failure)
|
||||
end
|
||||
end
|
||||
|
||||
def stop
|
||||
|
|
|
@ -14,6 +14,7 @@ module Guard
|
|||
wait_for_pid_action
|
||||
count += 1
|
||||
end
|
||||
!(count == 10)
|
||||
end
|
||||
|
||||
def stop
|
||||
|
@ -39,6 +40,14 @@ module Guard
|
|||
%{sh -c 'cd #{Dir.pwd} && rails s #{rails_options.join(' ')} &'}
|
||||
end
|
||||
|
||||
def pid_file
|
||||
File.expand_path("tmp/pids/#{options[:environment]}.pid")
|
||||
end
|
||||
|
||||
def pid
|
||||
File.file?(pid_file) ? File.read(pid_file).to_i : nil
|
||||
end
|
||||
|
||||
private
|
||||
def run_rails_command!
|
||||
system build_rails_command
|
||||
|
@ -52,10 +61,6 @@ module Guard
|
|||
0.5
|
||||
end
|
||||
|
||||
def pid_file
|
||||
File.expand_path("tmp/pids/#{options[:environment]}.pid")
|
||||
end
|
||||
|
||||
def kill_unmanaged_pid!
|
||||
if pid = unmanaged_pid
|
||||
system %{kill -INT #{pid}}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'guard/rails/runner'
|
||||
require 'fakefs/spec_helpers'
|
||||
|
||||
describe Guard::RailsRunner do
|
||||
let(:runner) { Guard::RailsRunner.new(options) }
|
||||
|
@ -9,6 +10,27 @@ describe Guard::RailsRunner do
|
|||
let(:default_options) { { :environment => environment, :port => port } }
|
||||
let(:options) { default_options }
|
||||
|
||||
describe '#pid' do
|
||||
include FakeFS::SpecHelpers
|
||||
|
||||
context 'pid file exists' do
|
||||
let(:pid) { 12345 }
|
||||
|
||||
before do
|
||||
File.open(runner.pid_file, 'w') { |fh| fh.print pid }
|
||||
end
|
||||
|
||||
it "should read the pid" do
|
||||
runner.pid.should == pid
|
||||
end
|
||||
end
|
||||
|
||||
context 'pid file does not exist' do
|
||||
it "should return nil" do
|
||||
runner.pid.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_rails_command' do
|
||||
context 'no daemon' do
|
||||
|
@ -42,7 +64,7 @@ describe Guard::RailsRunner do
|
|||
end
|
||||
|
||||
it "should act properly" do
|
||||
runner.start
|
||||
runner.start.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -56,7 +78,7 @@ describe Guard::RailsRunner do
|
|||
end
|
||||
|
||||
it "should act properly" do
|
||||
runner.start
|
||||
runner.start.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,7 +90,7 @@ describe Guard::RailsRunner do
|
|||
end
|
||||
|
||||
it "should act properly" do
|
||||
runner.start
|
||||
runner.start.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,5 +11,44 @@ describe Guard::Rails do
|
|||
guard
|
||||
end
|
||||
end
|
||||
|
||||
describe '#run_all' do
|
||||
let(:pid) { '12345' }
|
||||
|
||||
before do
|
||||
Guard::UI.expects(:info).with('Restarting Rails...')
|
||||
Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), anything)
|
||||
Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
|
||||
end
|
||||
|
||||
let(:runner_stub) { Guard::RailsRunner.any_instance.stubs(:restart) }
|
||||
|
||||
context 'with pid file' do
|
||||
before do
|
||||
runner_stub.returns(true)
|
||||
end
|
||||
|
||||
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/), anything)
|
||||
|
||||
guard.run_all
|
||||
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/), anything)
|
||||
|
||||
guard.run_all
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue