spec/kamerling/handler_spec.rb in kamerling-0.0.2 vs spec/kamerling/handler_spec.rb in kamerling-0.0.3

- old
+ new

@@ -1,41 +1,31 @@ require_relative '../spec_helper' +require_relative '../../lib/kamerling/addr' +require_relative '../../lib/kamerling/handler' +require_relative '../../lib/kamerling/message' +require_relative '../../lib/kamerling/receiver' +require_relative '../../lib/kamerling/registrar' +require_relative '../../lib/kamerling/uuid' -module Kamerling describe Handler do - describe '#handle' do - fakes :addr, :receiver, :registrar - let(:handler) { Handler.new receiver: receiver, registrar: registrar } +module Kamerling + describe Handler do + describe '#handle' do + fake :receiver, as: :class + fake :registrar, as: :class - it 'handles RGST inputs' do - input = 'RGST' + "\0" * 12 + '16B client UUID16B project UUID' - client_uuid = UUID['16B client UUID'] - project_uuid = UUID['16B project UUID'] - handler.handle input, addr - args = { - addr: addr, - client_uuid: client_uuid, - project_uuid: project_uuid, - } - registrar.must_have_received :register, [args] - end + let(:addr) { Addr.new } + let(:handler) { Handler.new(receiver: receiver, registrar: registrar) } - it 'handles RSLT inputs' do - input = 'RSLT' + "\0" * 12 + - '16B client UUID16B project UUID16B task UUIDdata' - client_uuid = UUID['16B client UUID'] - task_uuid = UUID['16B task UUID'] - handler.handle input, addr - args = { - addr: addr, - client_uuid: client_uuid, - data: 'data', - task_uuid: task_uuid, - } - receiver.must_have_received :receive, [args] - end + it 'handles RGST inputs' do + message = Message.parse('RGST') + handler.handle message, addr + registrar.must_have_received :register, [addr: addr, message: message] + end - it 'raises on unknown inputs' do - ex = -> { handler.handle 'MESS', addr }.must_raise Handler::UnknownInput - ex.message.must_equal 'MESS' + it 'handles RSLT inputs' do + message = Message.parse('RSLT') + handler.handle message, addr + receiver.must_have_received :receive, [addr: addr, message: message] + end end end -end end +end