Sha256: ba71536c4c9bbe522d7094a7e8e0a0f0ee85a6eefb0aa210f80833054706f019

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

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

describe Rib::Shell do
  behaves_like :rib

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

  describe '#loop' do
    def input str
      mock(@shell).get_input{str}
      @shell.loop.should.eq @shell
    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.should.eq nil
    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(@shell).warn(/rib: 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).warn(/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
      mock(@shell).warn(/^SyntaxError:/)
      @shell.eval_input('{').should.eq nil
      @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(@shell).after_loop
    lambda{ @shell.loop }.should.raise(RuntimeError)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rib-0.1.0 test/test_shell.rb