Sha256: 11739263840087ad0f431ee3514d8b772429d14e608f9aeb3b2278fea3966535

Contents?: true

Size: 1.93 KB

Versions: 10

Compression:

Stored size: 1.93 KB

Contents

require 'rib/test'
require 'rib/shell'

describe Rib::Shell do
  behaves_like :rib

  before do
    Rib.disable_plugins
    @shell = Rib::Shell.new
  end

  describe '#loop' do
    def input str
      mock(@shell).get_input{str}
      @shell.loop
      true.should.eq true
    end
    should 'exit'   do                    input('exit') end
    should 'quit'   do                    input('quit') end
    should 'ctrl+d' do mock(@shell).puts; input(nil)    end
  end

  describe '#loop_once' do
    def input str=nil
      if block_given?
        mock(@shell).get_input{ yield }
      else
        mock(@shell).get_input{ str }
      end
      @shell.loop_once
      true.should.eq true
    end

    should 'handles ctrl+c' do
      mock(@shell).handle_interrupt
      input{ raise Interrupt }
    end

    should 'prints result' do
      mock(@shell).puts('=> "mm"')
      input('"m" * 2')
    end

    should 'error in print_result' do
      mock(Rib).warn(/Error while printing result.*BOOM/m)
      input('obj = Object.new; def obj.inspect; raise "BOOM"; end; obj')
    end

    should 'print error from eval' do
      mock(@shell).puts(/RuntimeError/)
      input('raise "blah"')
    end
  end

  describe '#prompt' do
    should 'be changeable' do
      @shell.config[:prompt] = '> '
      @shell.prompt.should.eq  '> '
    end
  end

  describe '#eval_input' do
    before do
      @line = @shell.config[:line]
    end

    should 'line' do
      @shell.eval_input('10 ** 2')
      @shell.config[:line].should.eq @line + 1
    end

    should 'print error and increments line' do
      result, err = @shell.eval_input('{')
      result.should.eq nil
      err.should.kind_of?(SyntaxError)
      @shell.config[:line].should.eq @line + 1
    end
  end

  should 'call after_loop even if in_loop raises' do
    mock(@shell).loop_once{ raise 'boom' }
    mock(Rib).warn(is_a(String))
    mock(@shell).after_loop
    lambda{@shell.loop}.should.raise(RuntimeError)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rib-1.0.0 test/test_shell.rb
rib-0.9.9 test/test_shell.rb
rib-0.9.5 test/test_shell.rb
rib-0.9.5.pre.1 test/test_shell.rb
rib-0.9.5.pre.0 test/test_shell.rb
rib-0.9.4 test/test_shell.rb
rib-0.9.3 test/test_shell.rb
rib-0.9.2 test/test_shell.rb
rib-0.9.1 test/test_shell.rb
rib-0.9.0 test/test_shell.rb