Merge pull request #360 from kjwierenga/feature/require-posix-spawn
Feature/require posix spawn
This commit is contained in:
@@ -34,6 +34,7 @@ class Foreman::CLI < Thor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start(process=nil)
|
def start(process=nil)
|
||||||
|
require_posix_spawn_for_ruby_18!
|
||||||
check_procfile!
|
check_procfile!
|
||||||
load_environment!
|
load_environment!
|
||||||
engine.load_procfile(procfile)
|
engine.load_procfile(procfile)
|
||||||
@@ -137,6 +138,14 @@ private ######################################################################
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def require_posix_spawn_for_ruby_18!
|
||||||
|
begin
|
||||||
|
Kernel.require 'posix/spawn' # Use Kernel explicitly so we can mock the require call in the spec
|
||||||
|
rescue LoadError
|
||||||
|
error "foreman requires gem `posix-spawn` on Ruby #{RUBY_VERSION}. Please `gem install posix-spawn`."
|
||||||
|
end if Foreman.ruby_18?
|
||||||
|
end
|
||||||
|
|
||||||
def procfile
|
def procfile
|
||||||
case
|
case
|
||||||
when options[:procfile] then options[:procfile]
|
when options[:procfile] then options[:procfile]
|
||||||
|
|||||||
@@ -100,4 +100,12 @@ describe "Foreman::CLI", :fakefs do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "when posix-spawn is not present on ruby 1.8" do
|
||||||
|
it "should fail with an error" do
|
||||||
|
mock(Kernel).require('posix/spawn') { raise LoadError }
|
||||||
|
output = foreman("start -f #{resource_path("Procfile")}")
|
||||||
|
output.should == "ERROR: foreman requires gem `posix-spawn` on Ruby #{RUBY_VERSION}. Please `gem install posix-spawn`.\n"
|
||||||
|
end
|
||||||
|
end if running_ruby_18?
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
+12
-4
@@ -10,6 +10,15 @@ require "fakefs/spec_helpers"
|
|||||||
|
|
||||||
$:.unshift File.expand_path("../../lib", __FILE__)
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
||||||
|
|
||||||
|
begin
|
||||||
|
def running_ruby_18?
|
||||||
|
defined?(RUBY_VERSION) and RUBY_VERSION =~ /^1\.8\.\d+/
|
||||||
|
end
|
||||||
|
require 'posix/spawn' if running_ruby_18?
|
||||||
|
rescue LoadError
|
||||||
|
STDERR.puts "WARNING: foreman requires gem `posix-spawn` on Ruby #{RUBY_VERSION}. Please `gem install posix-spawn`."
|
||||||
|
end
|
||||||
|
|
||||||
def mock_export_error(message)
|
def mock_export_error(message)
|
||||||
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
|
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
|
||||||
end
|
end
|
||||||
@@ -36,8 +45,7 @@ end
|
|||||||
|
|
||||||
def forked_foreman(args)
|
def forked_foreman(args)
|
||||||
rd, wr = make_pipe
|
rd, wr = make_pipe
|
||||||
if Foreman.jruby_18? || Foreman.ruby_18?
|
if running_ruby_18?
|
||||||
require 'posix/spawn'
|
|
||||||
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => wr, :err => wr)
|
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => wr, :err => wr)
|
||||||
else
|
else
|
||||||
Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr)
|
Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr)
|
||||||
@@ -66,8 +74,7 @@ def fork_and_capture(&blk)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fork_and_get_exitstatus(args)
|
def fork_and_get_exitstatus(args)
|
||||||
pid = if Foreman.jruby_18? || Foreman.ruby_18?
|
pid = if running_ruby_18?
|
||||||
require 'posix/spawn'
|
|
||||||
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
|
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
|
||||||
else
|
else
|
||||||
Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
|
Process.spawn("bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
|
||||||
@@ -170,4 +177,5 @@ RSpec.configure do |config|
|
|||||||
config.order = 'rand'
|
config.order = 'rand'
|
||||||
config.include FakeFS::SpecHelpers, :fakefs
|
config.include FakeFS::SpecHelpers, :fakefs
|
||||||
config.mock_with :rr
|
config.mock_with :rr
|
||||||
|
config.backtrace_clean_patterns = []
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user