Sha256: 387a314a4126c6da171c74cb3e2a13f1a4e28312ed7e1f67b40e3b3e01ed3dc4

Contents?: true

Size: 1.75 KB

Versions: 39

Compression:

Stored size: 1.75 KB

Contents

require 'open3'
require 'rake/file_utils'
require 'shellwords'

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

        begin
          yield
        ensure
          ENV.replace(original)
        end
      end

      if Open3.respond_to?(:capture3) # 1.9+
        def shell_out(*command)
          stdout, stderr, status = Open3.capture3(*command)
          return stdout, filter(stderr), status
        end
      else # 1.8.7
        # popen3 doesn't provide the exit status so we fake it out.
        FakeProcessStatus = Struct.new(:exitstatus)

        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
      end

      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

    private

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

Version data entries

39 entries across 38 versions & 15 rubygems

Version Path
cvss-suite-1.0.8 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
tdiary-5.0.1 vendor/bundle/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.7 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
guesswhat-1.1.0 vendor/bundle/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
guesswhat-1.0.1 vendor/bundle/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
guesswhat-1.0.0 vendor/bundle/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
guesswhat-0.1.0 vendor/bundle/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.6 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.5 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.4 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.3 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.2 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.1 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
cvss-suite-1.0.0 vendor/cache/ruby/2.2.0/gems/rspec-support-3.4.0/lib/rspec/support/spec/shell_out.rb
rspec-support-3.5.0.beta3 lib/rspec/support/spec/shell_out.rb
rspec-support-3.5.0.beta2 lib/rspec/support/spec/shell_out.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/1.9.1/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
simplenet-client-0.2.0 ./vendor/bundle/ruby/2.0.0/gems/rspec-support-3.4.1/lib/rspec/support/spec/shell_out.rb
rspec-support-3.5.0.beta1 lib/rspec/support/spec/shell_out.rb