Sha256: feefe7b2c9b9251e41954193ef3c78ffd5b2d75b8286602bc9eb5a3127a0bdb9
Contents?: true
Size: 1.47 KB
Versions: 7
Compression:
Stored size: 1.47 KB
Contents
require_relative '../helper' require 'izanami/channel' module Mock class On < Struct.new(:buffer) def message buffer.each do |output| yield 'channel-id', output end end end end shared_examples 'Channel#read' do it 'reads the command output' do output = [] subject.read(id) { |line| output << line } output.should == expected end end describe Izanami::Channel do let(:mapper) { double('mapper') } let(:id) { '123' } subject { Izanami::Channel.new(mapper) } describe '#write' do it 'initiates a channel output instance' do subject.write(id).should be_instance_of(Izanami::Channel::Input) end end describe '#read' do let(:expected) { %w[ping pong] } context 'when the command has an output' do let(:command) do { 'id' => id, 'output' => "ping#{Izanami::Channel::SEPARATOR}pong" } end before do mapper.should_receive(:find).with(id).and_return(command) end it_should_behave_like 'Channel#read' end context 'when the command is been executed' do let(:command) { { 'id' => id, } } let(:on) { Mock::On.new(%W[ping pong #{Izanami::Channel::EOC}]) } before do mapper.should_receive(:find).with(id).and_return(command) mapper.should_receive(:subscribe).with(id).and_yield(on) mapper.should_receive(:unsubscribe).with(id) end it_should_behave_like 'Channel#read' end end end
Version data entries
7 entries across 7 versions & 1 rubygems