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

- old
+ new

@@ -1,9 +1,10 @@ require 'spec_helper' -describe Campfire::Connector do +describe Campfire::Connector, lita: true do let(:robot) { instance_double(Lita::Robot) } + let(:robot_id) { 2 } let(:subdomain) { 'mycampfire' } let(:apikey) { '2e9f45bb934c0fa13e9f19ee0901c316fda9fc1' } let(:rooms) { %w( 12345 ) } let(:options) { { subdomain: subdomain, apikey: apikey, rooms: rooms } } let(:campfire) { instance_double(Tinder::Campfire) } @@ -11,11 +12,10 @@ 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) @@ -23,16 +23,16 @@ end end context 'when connected to campfire' do before do + allow(campfire).to receive(:find_room_by_id).and_return(room) subject.connect end let(:callback) { instance_double(Campfire::Callback) } describe '#disconnect' do - it "leaves joined rooms" do expect(room).to receive(:leave) subject.disconnect end end @@ -49,10 +49,11 @@ end it 'passes options to underlying tinder lib' do allow(campfire).to receive(:find_room_by_id).and_return(room) subject.connect + allow(campfire).to receive_message_chain(:me,:id).and_return(robot_id) 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) @@ -61,12 +62,13 @@ 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 + allow(campfire).to receive_message_chain(:me,:id).and_return(robot_id) expect(Campfire::Callback).to receive(:new). - with(robot, room). + with(robot: robot, room: room, robot_id: robot_id). and_return(callback) expect(room).to receive(:join) expect(callback).to receive(:listen) expect(callback).to receive(:register_users) @@ -105,14 +107,9 @@ end end end 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' } it 'sets toom topic' do expect(room).to receive(:topic=).with(topic) subject.set_topic(room, topic) \ No newline at end of file