Require and use 'posix/spawn' when running ruby 1.8 without using Foreman.ruby_18? (which is the subject under test).

This commit is contained in:
Klaas Jan Wierenga
2013-05-03 21:29:17 +02:00
parent c3abaad353
commit ffc73366b2
+12 -4
View File
@@ -10,6 +10,15 @@ require "fakefs/spec_helpers"
$:.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)
lambda { yield }.should raise_error(Foreman::Export::Exception, message)
end
@@ -36,8 +45,7 @@ end
def forked_foreman(args)
rd, wr = make_pipe
if Foreman.jruby_18? || Foreman.ruby_18?
require 'posix/spawn'
if running_ruby_18?
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => wr, :err => wr)
else
Process.spawn("bundle exec bin/foreman #{args}", :out => wr, :err => wr)
@@ -66,8 +74,7 @@ def fork_and_capture(&blk)
end
def fork_and_get_exitstatus(args)
pid = if Foreman.jruby_18? || Foreman.ruby_18?
require 'posix/spawn'
pid = if running_ruby_18?
POSIX::Spawn.spawn({}, "bundle exec bin/foreman #{args}", :out => "/dev/null", :err => "/dev/null")
else
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.include FakeFS::SpecHelpers, :fakefs
config.mock_with :rr
config.backtrace_clean_patterns = []
end