Sha256: 7809844c108dcc5d06bae9c693a5fb18d1ee86d14efbd2d4f9ef5b3c9ff9de81

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

# encoding: utf-8
require 'fedux_org/stdlib/environment'

module ProxyTester
  module SpecHelper
    module Environment
      include FeduxOrg::Stdlib::Environment

      alias_method :with_environment, :isolated_environment 

      private

      def set_stdin(obj)
        $stdin = obj
      end

      def set_stderr(obj)
        $stderr = obj
      end

      def set_stdout(obj)
        $stdout = obj
      end

      def get_stdin
        $stdin
      end

      def get_stderr
        $stderr
      end

      def get_stdout
        $stdout
      end

      public

      def mock_io(io, *args, &block)
        raise RuntimeError, "Unsupported io: #{io}, allowed: stderr, stdin, stdout" unless [:stderr, :stdout, :stdin].include? io

        old_io = send("get_#{io}")

        io_obj = send("set_#{io}", StringIO.new)
        io_obj.puts(args.shift) until args.blank?
        io_obj.rewind

        block.call
      ensure
        io_obj = send("set_#{io}", old_io)
      end
    end
  end
end

RSpec.configure do |c|
  c.include ProxyTester::SpecHelper::Environment
  c.before(:suite) do
    %w{
      http_proxy
      https_proxy
      HTTP_PROXY
      HTTPS_PROXY
    }.each { |var| ENV.delete(var) }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
proxy_tester-0.1.2 spec/support/environment.rb
proxy_tester-0.1.1 spec/support/environment.rb
proxy_tester-0.1.0 spec/support/environment.rb
proxy_tester-0.0.9 spec/support/environment.rb
proxy_tester-0.0.8 spec/support/environment.rb
proxy_tester-0.0.7 spec/support/environment.rb
proxy_tester-0.0.6 spec/support/environment.rb
proxy_tester-0.0.5 spec/support/environment.rb