module PryTestHelpers - pry-0.10.1 Documentation

# module PryTestHelpers

A global space for storing temporary state during tests.

### Public Instance Methods

constant_scope(*names) { || ... } click to toggle source

    # File lib/pry/test/helper.rb, line 38
    def constant_scope(*names)
      names.each do |name|
        Object.remove_const name if Object.const_defined?(name)
      end

      yield
    ensure
      names.each do |name|
        Object.remove_const name if Object.const_defined?(name)
      end
    end

inject_var(name, value, b) click to toggle source

inject a variable into a binding

    # File lib/pry/test/helper.rb, line 31
    def inject_var(name, value, b)
      Pry.current[:pry_local] = value
      b.eval("#{name} = ::Pry.current[:pry_local]")
    ensure
      Pry.current[:pry_local] = nil
    end

mock_command(cmd, args=[], opts={}) click to toggle source

    # File lib/pry/test/helper.rb, line 64
    def mock_command(cmd, args=[], opts={})
      output = StringIO.new
      pry = Pry.new(output: output)
      ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
      Struct.new(:output, :return).new(output.string, ret)
    end

mock_exception(*mock_backtrace) click to toggle source

    # File lib/pry/test/helper.rb, line 71
    def mock_exception(*mock_backtrace)
      StandardError.new.tap do |e|
        e.define_singleton_method(:backtrace) { mock_backtrace }
      end
    end

temp_file(ext='.rb') { |file| ... } click to toggle source

Open a temp file and yield it to the block, closing it after @return [String] The path of the temp file

    # File lib/pry/test/helper.rb, line 52
    def temp_file(ext='.rb')
      file = Tempfile.new(['pry', ext])
      yield file
    ensure
      file.close(true) if file
      File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
    end

unindent(*args) click to toggle source

    # File lib/pry/test/helper.rb, line 60
    def unindent(*args)
      Pry::Helpers::CommandHelpers.unindent(*args)
    end