123456789_123456789_123456789_123456789_123456789_

Module: RSpec::Support::ShellOut

Relationships & Source Files
Namespace Children
Classes:
Defined in: rspec-support/lib/rspec/support/spec/shell_out.rb

Constant Summary

  • LINES_TO_IGNORE =
    # File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 58
    [
      # Ignore bundler warning.
      %r{bundler/source/rubygems},
      # Ignore bundler + rubygems warning.
      %r{site_ruby/\d\.\d\.\d/rubygems},
      %r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/rubygems},
      # This is required for windows for some reason
      %r{lib/bundler/rubygems},
      # This is a JRuby file that generates warnings on 9.0.3.0
      %r{lib/ruby/stdlib/jar},
      # This is a JRuby file that generates warnings on 9.1.7.0
      %r{org/jruby/RubyKernel\.java},
      # This is a JRuby gem that generates warnings on 9.1.7.0
      %r{ffi-1\.13\.\d+-java},
      %r{uninitialized constant FFI},
      # These are related to the above, there is a warning about io from FFI
      %r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/io},
      %r{io/console on JRuby shells out to stty for most operations},
      # This is a JRuby 9.1.17.0 error on Github Actions
      %r{io/console not supported; tty will not be manipulated},
      # This is a JRuby 9.2.1.x error
      %r{jruby/kernel/gem_prelude},
      %r{lib/jruby\.jar!/jruby/preludes},
      # Ignore some JRuby errors for gems
      %r{jruby/\d\.\d(\.\d)?/gems/aruba},
      %r{jruby/\d\.\d(\.\d)?/gems/ffi},
    ]

Instance Method Summary

Instance Method Details

#filter(output) (private)

See additional method definition at line 98.

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 104

def filter(output)
  output.each_line.reject do |line|
    line.include?("lib/ruby/shared/rubygems")
  end.join($/)
end

#run_ruby_with_current_load_path(ruby_command, *flags)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 43

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

#shell_out(*command)

See additional method definition at line 22.

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 30

def shell_out(*command)
  stdout, stderr, status = Open3.capture3(*command)
  return stdout, filter(stderr), status
end

#strip_known_warnings(input)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 87

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

#with_env(vars)

[ GitHub ]

  
# File 'rspec-support/lib/rspec/support/spec/shell_out.rb', line 10

def with_env(vars)
  original = ENV.to_hash
  vars.each { |k, v| ENV[k] = v }

  begin
    yield
  ensure
    ENV.replace(original)
  end
end