Sha256: 8ef7b12b27d2d9c338232ce00a3c5d47a5c91d5932781c21a4a3a4f493566267

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 KB

Contents

require 'test_helper'

module Vedeu

  describe Input do

    let(:reader)    { Vedeu::Terminal }
    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

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.4.6 test/lib/vedeu/input/input_test.rb
vedeu-0.4.5 test/lib/vedeu/input/input_test.rb
vedeu-0.4.4 test/lib/vedeu/input/input_test.rb
vedeu-0.4.3 test/lib/vedeu/input/input_test.rb
vedeu-0.4.2 test/lib/vedeu/input/input_test.rb
vedeu-0.4.1 test/lib/vedeu/input/input_test.rb
vedeu-0.4.0 test/lib/vedeu/input/input_test.rb
vedeu-0.3.5 test/lib/vedeu/input/input_test.rb