module RSpec::Support::ShellOut
def filter(output)
def filter(output) output.each_line.reject do |line| line.include?("lib/ruby/shared/rubygems") end.join($/) end
def filter(output)
def filter(output) output end
def run_ruby_with_current_load_path(ruby_command, *flags)
def run_ruby_with_current_load_path(ruby_command, *flags) command = [ FileUtils::RUBY, "-I#{$LOAD_PATH.map(&:shellescape).join(File::PATH_SEPARATOR)}", "-e", ruby_command, *flags ] # Unset these env vars because `ruby -w` will issue warnings whenever # they are set to non-default values. with_env 'RUBY_GC_HEAP_FREE_SLOTS' => nil, 'RUBY_GC_MALLOC_LIMIT' => nil, 'RUBY_FREE_MIN' => nil do shell_out(*command) end end
def shell_out(*command)
def shell_out(*command) stdout, stderr, status = Open3.capture3(*command) return stdout, filter(stderr), status end
def shell_out(*command)
def shell_out(*command) stdout = stderr = nil Open3.popen3(*command) do |_in, out, err| stdout = out.read stderr = err.read end status = FakeProcessStatus.new(0) return stdout, filter(stderr), status end
def strip_known_warnings(input)
def strip_known_warnings(input) input.split("\n").reject do |l| LINES_TO_IGNORE.any? { |to_ignore| l =~ to_ignore } || # Remove blank lines l == "" || l.nil? end.join("\n") end
def with_env(vars)
def with_env(vars) original = ENV.to_hash vars.each { |k, v| ENV[k] = v } begin yield ensure ENV.replace(original) end end