Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 69 lines (59 sloc) 1.388 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
require 'bacon'
require 'bacon/bits'
require 'mocha-on-bacon'
require 'bond'
require 'rbconfig'

module TestHelpers
  extend self
  def mock_irb
    unless Object.const_defined?(:IRB)
      eval %[
module ::IRB
class<<self; attr_accessor :CurrentContext; end
module InputCompletor; CompletionProc = lambda {|e| [] }; end
end
]
      ::IRB.CurrentContext = stub(:workspace => stub(:binding => binding))
    end
  end

  def capture_stderr(&block)
    original_stderr = $stderr
    $stderr = fake = StringIO.new
    begin
      yield
    ensure
      $stderr = original_stderr
    end
    fake.string
  end

  def capture_stdout(&block)
    original_stdout = $stdout
    $stdout = fake = StringIO.new
    begin
      yield
    ensure
      $stdout = original_stdout
    end
    fake.string
  end

  def tab(full_line, last_word=full_line)
    Bond.agent.weapon.stubs(:line_buffer).returns(full_line)
    Bond.agent.call(last_word)
  end

  def complete(*args, &block)
    Bond.complete(*args, &block)
  end

  def valid_readline
    Class.new { def self.setup(arg); end; def self.line_buffer; end }
  end

  def reset
    M.reset
    M.debrief :readline => TestHelpers.valid_readline
  end
end

class Bacon::Context
  include TestHelpers
end

# Default settings
Bond::M.debrief(:readline => TestHelpers.valid_readline, :debug => true)
include Bond
Something went wrong with that request. Please try again.