Skip to content

Commit

Permalink
Require and use 'posix/spawn' when running ruby 1.8 without using For…
Browse files Browse the repository at this point in the history
…eman.ruby_18? (which is the subject under test).
  • Loading branch information
kjwierenga committed May 3, 2013
1 parent c3abaad commit ffc7336
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

$:.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
Expand All @@ -36,8 +45,7 @@ def foreman(args)

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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -170,4 +177,5 @@ def capture_stdout
config.order = 'rand'
config.include FakeFS::SpecHelpers, :fakefs
config.mock_with :rr
config.backtrace_clean_patterns = []
end

0 comments on commit ffc7336

Please sign in to comment.