spec/unit/realtime/channel_spec.rb in ably-0.8.2 vs spec/unit/realtime/channel_spec.rb in ably-0.8.3

- old
+ new

@@ -69,10 +69,11 @@ describe '#publish name argument' do let(:encoded_value) { random_str.encode(encoding) } before do allow(subject).to receive(:create_message).and_return('message_stubbed') + allow(subject).to receive(:attach).and_return(:true) end context 'as UTF_8 string' do let(:encoding) { Encoding::UTF_8 } @@ -106,12 +107,12 @@ end context 'as Nil' do let(:encoded_value) { nil } - it 'raises an argument error' do - expect { subject.publish(encoded_value, 'data') }.to raise_error ArgumentError, /must be a String/ + it 'is permitted' do + expect(subject.publish(encoded_value, 'data')).to eql('message_stubbed') end end end describe 'callbacks' do @@ -157,10 +158,14 @@ let(:focus_event) { 'focus' } let(:focus_message) { instance_double('Ably::Models::Message', name: focus_event, encode: nil, decode: nil) } let(:blur_message) { instance_double('Ably::Models::Message', name: 'blur', encode: nil, decode: nil) } context '#subscribe' do + before do + allow(subject).to receive(:attach).and_return(:true) + end + specify 'without a block raises an invalid ArgumentError' do expect { subject.subscribe }.to raise_error ArgumentError end specify 'with no event name specified subscribes the provided block to all events' do @@ -197,11 +202,13 @@ context '#unsubscribe' do let(:callback) do Proc.new { |message| message_history[:received] += 1 } end + before do - subject.subscribe(click_event, &callback) + allow(subject).to receive(:attach).and_return(:true) + subject.subscribe click_event, &callback end specify 'with no event name specified unsubscribes that block from all events' do subject.unsubscribe &callback subject.__incoming_msgbus__.publish(:message, click_message)