Sha256: 78459a682e32661d1c6a0e5fbae11e3d496c39c23943284e22f609672c1bf13e

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

require 'test_helper'

module Vedeu

  describe Input do

    let(:reader)    { mock }
    let(:keypress)  { 'a' }
    let(:described) { Vedeu::Input }
    let(:instance)  { described.new(reader) }

    before { reader.stubs(:read).returns(keypress) }

    describe '#initialize' do
      it { instance.must_be_instance_of(Input) }
      it { instance.instance_variable_get('@reader').must_equal(reader) }
    end

    describe '.capture' do
      context 'when the key is not special' do
        before { Vedeu.stubs(:trigger).returns([false]) }

        it 'triggers an event associated with the key pressed' do
          Input.capture(reader).must_equal([false])
        end
      end

      context 'when the key is special' do
        let(:keypress) { "\e" }

        before { Vedeu.stubs(:trigger).raises(ModeSwitch) }

        it 'switches the terminal mode when escape is pressed' do
          proc { Input.capture(reader) }.must_raise(ModeSwitch)
        end
      end
    end

  end # Input

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.3.4 test/lib/vedeu/input/input_test.rb