require_relative "../../helper" require_relative "../../../lib/fabriq/skype" describe Fabriq::Skype do before do @adapter = mock('Adapter') Fabriq::Skype.adapter = @adapter end describe '#rooms' do it "returns Fabriq::Adapter.rooms" do @adapter.stubs(:rooms).returns( [ "r1", "r2" ] ) Fabriq::Skype.rooms.must_equal( ["r1", "r2"] ) end end describe '#room_by_id' do it "returns the first matching room" do room = stub('Room', :id => "room123") @adapter.stubs(:rooms).returns([room]) Fabriq::Skype.room_by_id("room123").must_equal(room) end it "returns nil on no match" do @adapter.stubs(:rooms).returns([]) Fabriq::Skype.room_by_id("room123").must_be_nil end end describe '#send_message' do it "appends messages to the outgoing-message-collection of the proxy" do message = mock('Message') @adapter.expects(:enqueue_outgoing_message).with(message) Fabriq::Skype.send_message(message) end end describe '#listen_for_messages_to_self' do before do @callback = -> {} @message = mock('Message') @message.stubs(:private_session?).returns(false) @message.stubs(:direct?).returns(false) @adapter.stubs(:subscribe_to_incoming_messages).yields(@message) end it "subscribes to incoming messages" do @adapter.expects(:subscribe_to_incoming_messages) Fabriq::Skype.listen_for_messages_to_self end it "does not yield the message by default" do @callback.expects(:call).never Fabriq::Skype.listen_for_messages_to_self(&@callback) end it "yields the received message if it was delivered to a private session" do @callback.expects(:call).with(@message) @message.stubs(:private_session?).returns(true) Fabriq::Skype.listen_for_messages_to_self(&@callback) end it "yields the received message if its a direct message" do @callback.expects(:call).with(@message) @message.stubs(:direct?).returns(true) Fabriq::Skype.listen_for_messages_to_self(&@callback) end end end