spec/lita/adapters/campfire/connector_spec.rb in lita-campfire-0.1.3 vs spec/lita/adapters/campfire/connector_spec.rb in lita-campfire-0.1.4

- old
+ new

@@ -1,98 +1,123 @@ require 'spec_helper' describe Campfire::Connector do - let(:robot) { double } + let(:robot) { instance_double(Lita::Robot) } let(:subdomain) { 'mycampfire' } let(:apikey) { '2e9f45bb934c0fa13e9f19ee0901c316fda9fc1' } let(:rooms) { %w( 12345 ) } let(:options) { { subdomain: subdomain, apikey: apikey, rooms: rooms } } - let(:campfire) { double } + let(:campfire) { instance_double(Tinder::Campfire) } + let(:room) { instance_double(Tinder::Room) } subject { described_class.new(robot, options) } before do allow(Tinder::Campfire).to receive(:new).and_return(campfire) + allow(campfire).to receive(:find_room_by_id).and_return(room) end describe '#connect' do it 'connects the campfire connection' do expect(Tinder::Campfire).to receive(:new).with(subdomain, token: apikey) subject.connect end end - describe '#join_rooms' do - describe 'when I have access to the room' do - let(:room) { double('Room', id: 666) } + context 'when connected to campfire' do + before do + subject.connect + end + let(:callback) { instance_double(Campfire::Callback) } - before do - allow(campfire).to receive(:find_room_by_id).and_return(room) - subject.connect + describe '#disconnect' do + + it "leaves joined rooms" do + expect(room).to receive(:leave) + subject.disconnect end + end - it 'joins each room, registers the users and listens for messages' do - expect(Campfire::Callback).to receive(:new). - with(robot, room). - and_return(callback = double('Callback')) + describe 'when tinder options are set' do + let(:tinder_options) { { timeout: 30 } } + let(:options) do + { + subdomain: subdomain, + apikey: apikey, + rooms: rooms, + tinder_options: tinder_options + } + end - expect(room).to receive(:join) - expect(callback).to receive(:listen) - expect(callback).to receive(:register_users) + it 'passes options to underlying tinder lib' do + allow(campfire).to receive(:find_room_by_id).and_return(room) + subject.connect + allow(Campfire::Callback).to receive(:new).and_return(callback) + allow(room).to receive(:join) + allow(callback).to receive(:register_users) + expect(callback).to receive(:listen).with(tinder_options) subject.join_rooms end end - describe "when I don't have access to the room" do - before do - allow(campfire).to receive(:find_room_by_id).and_return(nil) - subject.connect - end + describe '#join_rooms' do + describe 'when I have access to the room' do + it 'joins each room, registers the users and listens for messages' do + expect(Campfire::Callback).to receive(:new). + with(robot, room). + and_return(callback) - it 'raises an exception' do - expect { subject.join_rooms }.to raise_error(Campfire::RoomNotAvailable) + expect(room).to receive(:join) + expect(callback).to receive(:listen) + expect(callback).to receive(:register_users) + + subject.join_rooms + end end - end - end - describe '#send_messages' do - let(:room) { double } + describe "when I don't have access to the room" do + before do + allow(campfire).to receive(:find_room_by_id).and_return(nil) + end - before do - allow(campfire).to receive(:find_room_by_id).and_return(room) - subject.connect + it 'raises an exception' do + expect { subject.join_rooms }.to raise_error(Campfire::RoomNotAvailable) + end + end end - context 'with a one line message' do - let(:message) { "I'm gonna drink 'til I reboot." } + describe '#send_messages' do + context 'with a one line message' do + let(:message) { "I'm gonna drink 'til I reboot." } - it 'speaks each message into room' do - expect(room).to receive(:speak).with(message) - subject.send_messages double(id: 1), [ message ] + it 'speaks each message into room' do + expect(room).to receive(:speak).with(message) + subject.send_messages room, [ message ] + end end - end - context 'with a multi line message' do - let(:message) { "I'm gonna drink 'til I reboot.\nNow I'm too drunk" } + context 'with a multi line message' do + let(:message) { "I'm gonna drink 'til I reboot.\nNow I'm too drunk" } - it 'pastes each message into room' do - expect(room).to receive(:paste).with(message) - subject.send_messages double(id: 1), [ message ] + it 'pastes each message into room' do + expect(room).to receive(:paste).with(message) + subject.send_messages room, [ message ] + end end end - end - describe '#disconnect' do - let(:room) { double('Room', id: 666) } + describe '#set_topic' do + before do + allow(Lita.logger).to receive(:info) + allow(campfire).to receive(:find_room_by_id).and_return(room) + subject.connect + end + let(:topic) { 'Let it be wadus' } - before do - allow(campfire).to receive(:find_room_by_id).and_return(room) - subject.connect - end - - it "leaves joined rooms" do - expect(room).to receive(:leave) - subject.disconnect + it 'sets toom topic' do + expect(room).to receive(:topic=).with(topic) + subject.set_topic(room, topic) + end end end end \ No newline at end of file