require 'test_helper' module Vedeu describe API do let(:event) { mock('Event') } before { Event.stubs(:new).returns(event) } describe '.event' do it 'registers and returns the event' do Vedeu.event(:some_event).must_equal( { events: [event], } ) end end describe '.unevent' do it 'unregister the event by name' do Vedeu.event(:calcium) { proc { |x| x } } Vedeu.unevent(:calcium).wont_include(:calcium) end end describe '.events' do it 'returns the Events singleton' do Vedeu.events.must_be_instance_of(Vedeu::Events) end end describe '.height' do it 'returns the terminal height' do IO.console.stub(:winsize, [24, 40]) do Vedeu.height.must_equal(24) end end end describe '.interface' do it 'creates and stores a new interface' do Vedeu::Buffers.reset Vedeu.interface('Vedeu.interface').must_be_instance_of(API::Interface) end end describe '.keypress' do before { event.stubs(:trigger).returns(nil) } it 'returns nil' do Vedeu.keypress('k').must_equal(nil) end end describe '.log' do it 'writes the message to the log file when debugging is enabled' do Configuration.stub(:debug?, true) do Vedeu.log('some message...').must_equal(true) end end it 'returns nil when debugging is disabled' do Configuration.stub(:debug?, false) do Vedeu.log('some message...').must_equal(nil) end end end describe '.trigger' do it 'triggers the specifed event and returns the collection of events' \ ' which this trigger triggers' do Vedeu.trigger(:vedeu_trigger_event, :event_arguments).must_equal([]) end end describe '.use' do it 'raises an exception if the interface has not been defined' do Vedeu::Buffers.reset proc { Vedeu.use('some_interface') }.must_raise(Vedeu::EntityNotFound) end it 'returns' do Vedeu.interface('some_interface') Vedeu.use('some_interface').must_be_instance_of(Vedeu::Interface) end end describe '.view' do it 'returns the view attributes for an interface (see View)' do Vedeu.view('some_interface').must_equal( { interfaces: [{ name: "some_interface", group: "", lines: [], colour: {}, style: "", geometry: {}, cursor: true, delay: 0.0 }] } ) end end describe '.views' do it 'returns the view attributes for a composition (a collection of ' \ 'interfaces)' do Vedeu.views do view 'osmium' view 'iridium' end.must_equal( { interfaces: [ { name: "osmium", group: "", lines: [], colour: {}, style: "", geometry: {}, cursor: true, delay: 0.0 }, { name: "iridium", group: "", lines: [], colour: {}, style: "", geometry: {}, cursor: true, delay: 0.0 } ] } ) end it 'raises an exception if a block was not given' do proc { Vedeu.views }.must_raise(InvalidSyntax) end end describe '.width' do it 'returns the terminal width' do IO.console.stub(:winsize, [24, 40]) do Vedeu.width.must_equal(40) end end end end end