test/test_utils.rb in tzinfo-1.0.1 vs test/test_utils.rb in tzinfo-1.1.0

- old
+ new

@@ -72,15 +72,17 @@ ensure $-v = old_verbose end end - def safe_test(level = 1) - # Don't run on JRuby. It doesn't support SAFE levels. - if RUBY_PLATFORM != 'java' + def safe_test(options = {}) + # JRuby and Rubinus don't support SAFE levels. + available = !(defined?(RUBY_ENGINE) && %w(jruby rbx).include?(RUBY_ENGINE)) + + if available || options[:unavailable] != :skip thread = Thread.new do - $SAFE = level + $SAFE = options[:level] || 1 if available yield end thread.join end @@ -97,14 +99,32 @@ def assert_sub_process_returns(expected_lines, code, extra_load_path = [], required = ['tzinfo']) ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']) load_path = [TZINFO_LIB_DIR] + extra_load_path - load_path = load_path.collect {|p| "-I \"#{p}\""}.join(' ') - required = required.collect {|r| "-r \"#{r}\""}.join(' ') + # If RubyGems is loaded in the current process, then require it in the + # sub-process, as it may be needed in order to require dependencies. + if defined?(Gem) && Gem.instance_of?(Module) + required = ['rubygems'] + required + end + + if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' + # Stop Rubinus from operating as irb. + args = ' -' + else + args = '' + end + + IO.popen("\"#{ruby}\"#{args}", 'r+') do |process| + load_path.each do |p| + process.puts("$:.unshift('#{p.gsub("'", "\\\\'")}')") + end - IO.popen("\"#{ruby}\" #{load_path} #{required}", 'r+') do |process| + required.each do |r| + process.puts("require '#{r.gsub("'", "\\\\'")}'") + end + process.puts(code) process.flush process.close_write actual_lines = process.readlines