class Object

Public Instance Methods

check(str, err=nil) click to toggle source
# File lib/rib/test/multiline.rb, line 27
def check str, err=nil
  lines = str.split("\n")
  lines[0...-1].each{ |line|
    input(line)
    shell.loop_once
  }
  input_done(lines.last, err)
end
history_file() click to toggle source
# File lib/rib/test/history.rb, line 22
def history_file
  tempfile.path
end
input(str) click to toggle source
# File lib/rib/test/multiline.rb, line 11
def input str
  setup_input(str)
  mock(shell).throw(:rib_multiline)
end
input_done(str, err=nil) click to toggle source
# File lib/rib/test/multiline.rb, line 16
def input_done str, err=nil
  setup_input(str)
  if err
    mock(shell).print_eval_error(is_a(err)){}
  else
    mock(shell).print_result(is_a(Object)){}
  end
  shell.loop_once
  ok
end
main() click to toggle source
# File lib/rib/test.rb, line 118
def main
  'rib'
end
new_shell(opts={}) { |result| ... } click to toggle source
# File lib/rib/test.rb, line 22
def new_shell opts={}
  result = Rib::Shell.new(
    {:binding => Object.new.instance_eval{binding}}.
    merge(opts))
  yield(result) if block_given?
  result.before_loop
end
readline?() click to toggle source
# File lib/rib/test.rb, line 36
def readline?
  Rib.constants.map(&:to_s).include?('Readline') &&
    Rib::Readline.enabled?
end
setup_input(str) click to toggle source
# File lib/rib/test/multiline.rb, line 3
def setup_input str
  if readline?
    stub_readline(:mock)
  else
    mock($stdin).gets{ str.chomp }
  end
end
shell(opts={}) click to toggle source
# File lib/rib/test.rb, line 18
def shell opts={}
  @shell ||= new_shell(opts)
end
stub_output() click to toggle source
# File lib/rib/test.rb, line 30
def stub_output
  stub(shell).print(is_a(String)){}
  stub(shell).puts(is_a(String)){}
  stub(shell).puts{}
end
stub_readline(meth=:stub) click to toggle source
# File lib/rib/test.rb, line 41
def stub_readline meth=:stub
  send(meth, ::Readline).readline(is_a(String), true) do
    (::Readline::HISTORY << str.chomp).last
  end
end
tempfile() click to toggle source
# File lib/rib/test/history.rb, line 18
def tempfile
  @tempfile ||= Tempfile.new('rib')
end
test_for(*plugins, &block) click to toggle source
# File lib/rib/test.rb, line 48
def test_for *plugins, &block
  require 'rib/all' # exhaustive tests
  rest = Rib.plugins - plugins

  before do
    Rib.enable_plugins(plugins)
    Rib.disable_plugins(rest)
  end

  describe "enabling #{plugins}" do
    block.call

    case ENV['TEST_LEVEL']
    when '0'
    when '1'
      test_level1(rest, block)
    when '2'
      test_level2(rest, block)
    when '3'
      test_level3(rest, block)
    else # test_level3 is too slow because of rr (i guess)
      test_level2(rest, block)
    end
  end
end
test_level1(rest, block) click to toggle source
# File lib/rib/test.rb, line 74
def test_level1 rest, block
  rest.each{ |target|
    target.enable

    describe "also enabling #{target}" do
      block.call
    end

    target.disable
  }
end
test_level2(rest, block) click to toggle source
# File lib/rib/test.rb, line 86
def test_level2 rest, block
  rest.combination(2).each{ |targets|
    Rib.enable_plugins(targets)

    describe "also enabling #{targets.join(', ')}" do
      block.call
    end

    Rib.disable_plugins(targets)
  }
end
test_level3(rest, block) click to toggle source
# File lib/rib/test.rb, line 98
def test_level3 rest, block
  if rest.empty?
    block.call
  else
    rest[0].enable

    describe "also enabling #{rest[0]}" do
      test_level3(rest[1..-1], block)
    end

    rest[0].disable

    describe "disabling #{rest[0]}" do
      test_level3(rest[1..-1], block)
    end
  end
end