Sha256: 54e8fa2e8add5c80db32aa2d075af7fc6220cc0e344bdea24551e19947f32708

Contents?: true

Size: 730 Bytes

Versions: 77

Compression:

Stored size: 730 Bytes

Contents

def mock_pry(*args)
  args.flatten!
  binding = args.first.is_a?(Binding) ? args.shift : binding()

  input = InputTester.new(*args)
  output = StringIO.new

  redirect_pry_io(input, output) do
    binding.pry
  end

  output.string
end

# Set I/O streams. Out defaults to an anonymous StringIO.
def redirect_pry_io(new_in, new_out = StringIO.new)
  old_in = Pry.input
  old_out = Pry.output

  Pry.input = new_in
  Pry.output = new_out
  begin
    yield
  ensure
    Pry.input = old_in
    Pry.output = old_out
  end
end

class InputTester
  def initialize(*actions)
    @orig_actions = actions.dup
    @actions = actions
  end

  def readline(*)
    @actions.shift
  end

  def rewind
    @actions = @orig_actions.dup
  end
end

Version data entries

77 entries across 77 versions & 5 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/pry-0.9.12.6/spec/helpers/mock_pry.rb
pry-0.9.12.6 spec/helpers/mock_pry.rb
pry-0.9.12.6-i386-mswin32 spec/helpers/mock_pry.rb
pry-0.9.12.6-i386-mingw32 spec/helpers/mock_pry.rb
pry-0.9.12.6-java spec/helpers/mock_pry.rb
pry-0.9.12.5 spec/helpers/mock_pry.rb
pry-0.9.12.5-i386-mswin32 spec/helpers/mock_pry.rb
pry-0.9.12.5-i386-mingw32 spec/helpers/mock_pry.rb
pry-0.9.12.5-java spec/helpers/mock_pry.rb
pry-0.9.12.4 spec/helpers/mock_pry.rb
pry-0.9.12.4-i386-mswin32 spec/helpers/mock_pry.rb
pry-0.9.12.4-i386-mingw32 spec/helpers/mock_pry.rb
pry-0.9.12.4-java spec/helpers/mock_pry.rb
pry-0.9.12.3 spec/helpers/mock_pry.rb
pry-0.9.12.3-i386-mswin32 spec/helpers/mock_pry.rb
pry-0.9.12.3-i386-mingw32 spec/helpers/mock_pry.rb
pry-0.9.12.3-java spec/helpers/mock_pry.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/spec/helpers/mock_pry.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/helpers/mock_pry.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/pry-0.9.12.2/spec/helpers/mock_pry.rb