Module: RSpec::Support::ShellOut
- Defined in:
- lib/rspec/support/spec/shell_out.rb
Defined Under Namespace
Classes: FakeProcessStatus
Constant Summary
collapse
- LINES_TO_IGNORE =
[
%r{bundler/source/rubygems},
%r{site_ruby/\d\.\d\.\d/rubygems},
%r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/rubygems},
%r{lib/bundler/rubygems},
%r{lib/ruby/stdlib/jar},
%r{org/jruby/RubyKernel\.java},
%r{ffi-1\.13\.\d+-java},
%r{uninitialized constant FFI},
%r{jruby-\d\.\d\.\d+\.\d/lib/ruby/stdlib/io},
%r{io/console on JRuby shells out to stty for most operations},
%r{io/console not supported; tty will not be manipulated},
%r{jruby/kernel/gem_prelude},
%r{lib/jruby\.jar!/jruby/preludes},
%r{jruby/\d\.\d(\.\d)?/gems/aruba},
%r{jruby/\d\.\d(\.\d)?/gems/ffi},
]
Instance Method Summary
collapse
Instance Method Details
#run_ruby_with_current_load_path(ruby_command, *flags) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File '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
]
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) ⇒ Object
22
23
24
25
|
# File 'lib/rspec/support/spec/shell_out.rb', line 22
def shell_out(*command)
stdout, stderr, status = Open3.capture3(*command)
return stdout, filter(stderr), status
end
|
#strip_known_warnings(input) ⇒ Object
87
88
89
90
91
92
93
|
# File '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 } ||
l == "" || l.nil?
end.join("\n")
end
|
#with_env(vars) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File '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
|