guard-rails/spec/lib/guard/rails/runner_spec.rb

123 lines
3.0 KiB
Ruby
Raw Normal View History

require 'spec_helper'
require 'guard/rails/runner'
2011-06-01 14:28:32 +00:00
require 'fakefs/spec_helpers'
describe Guard::RailsRunner do
let(:runner) { Guard::RailsRunner.new(options) }
let(:environment) { 'development' }
let(:port) { 3000 }
let(:default_options) { { :environment => environment, :port => port } }
let(:options) { default_options }
2011-06-01 14:28:32 +00:00
describe '#pid' do
include FakeFS::SpecHelpers
context 'pid file exists' do
let(:pid) { 12345 }
before do
2011-09-14 18:19:54 +00:00
FileUtils.mkdir_p File.split(runner.pid_file).first
2011-06-01 14:28:32 +00:00
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
it "should not have a daemon switch" do
2012-09-08 22:26:21 +00:00
runner.build_rails_command.last.should_not match(%r{ -d})
end
end
context 'daemon', :unless => RUBY_PLATFORM =~ /mswin|msys|mingw/ do
let(:options) { default_options.merge(:daemon => true) }
it "should have a daemon switch" do
2012-09-08 22:26:21 +00:00
runner.build_rails_command.last.should match(%r{ -d})
end
end
context 'debugger' do
let(:options) { default_options.merge(:debugger => true) }
it "should have a debugger switch" do
2012-09-08 22:26:21 +00:00
runner.build_rails_command.last.should match(%r{ -u})
end
end
context 'custom server' do
let(:options) { default_options.merge(:server => 'thin') }
it "should have the server name" do
2012-09-08 22:26:21 +00:00
runner.build_rails_command.last.should match(%r{thin})
end
end
end
describe '#start' do
2012-09-08 22:26:21 +00:00
include FakeFS::SpecHelpers
let(:kill_expectation) { runner.expects(:kill_unmanaged_pid!) }
let(:pid_stub) { runner.stubs(:has_pid?) }
before do
2012-09-08 22:26:21 +00:00
FileUtils.mkdir_p File.split(runner.pid_file).first
process = mock('process')
process.stubs(:pid).returns(123)
runner.expects(:run_rails_command!).once.returns(process)
end
context 'do not force run' do
before do
pid_stub.returns(true)
kill_expectation.never
2012-09-08 22:26:21 +00:00
runner.stubs(:rails_running?).once.returns(true)
end
it "should act properly" do
2011-06-01 14:28:32 +00:00
runner.start.should be_true
end
end
context 'force run' do
let(:options) { default_options.merge(:force_run => true) }
before do
pid_stub.returns(true)
kill_expectation.once
2012-09-08 22:26:21 +00:00
runner.stubs(:rails_running?).once.returns(true)
end
it "should act properly" do
2011-06-01 14:28:32 +00:00
runner.start.should be_true
end
end
context "don't write the pid" do
2012-09-08 22:26:21 +00:00
let(:options) { default_options.merge(:timeout => 0.1) }
before do
pid_stub.returns(false)
kill_expectation.never
2012-09-08 22:26:21 +00:00
runner.stubs(:rails_running?).once.returns(false)
end
it "should act properly" do
2011-06-01 14:28:32 +00:00
runner.start.should be_false
end
end
end
2011-06-01 14:42:53 +00:00
end