Sha256: 2c54c1dafe028d6d3154b7f336d0ed99321cb5f84bab63c8226c5736df704428

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

describe Noam::Player do
  def make_message(message)
    Noam::Message::Playable.new('host', 'event', message)
  end

  class MockTcpSocket
    def published_messages
      @published_messages ||= []
    end

    def print(message)
      published_messages << message
    end

    def close; end

    def flush; end
  end

  let(:player) { described_class.new('0.0.0.0', 1234) }
  let(:mock_socket) { MockTcpSocket.new }

  before do
    TCPSocket.stubs(:new).returns(mock_socket)
  end

  describe "connected?" do
    it "returns true if the socket is open" do
      player.stop
      expect(player.connected?).to be_truthy
    end

    it "returns false if a write to the socket has failed" do
      mock_socket.stubs(:print).raises(Errno::EPIPE.new)
      player.put(make_message("message"))
      player.stop
      expect(player.connected?).to be_falsey
    end
  end

  describe "stop" do
    it "publishes the remaning messages in the queue" do
      100.times do
        player.put(make_message("message"))
      end
      player.stop
      expect(mock_socket.published_messages.size).to eq(100)
    end
  end

  describe "stop!" do
    it "does not finish the queue" do
      100.times do
        player.put(make_message("message"))
      end
      player.stop!
      expect(mock_socket.published_messages.size).to be < 100
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
noam_lemma-0.2.1.3 spec/noam_lemma/player_spec.rb