Sha256: b0e19f078ea33ed88a6f38d20b98bf8e032189beb99f509897828c05f8d5fb3f

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require 'unit_spec_helper'

describe Rpush::Daemon::Dispatcher::Tcp do
  let(:app) { double }
  let(:delivery) { double(:perform => nil) }
  let(:delivery_class) { double(:new => delivery) }
  let(:notification) { double }
  let(:batch) { double }
  let(:connection) { double(Rpush::Daemon::TcpConnection, :connect => nil) }
  let(:host) { 'localhost' }
  let(:port) { 1234 }
  let(:host_proc) { Proc.new { |app| [host, port] } }
  let(:dispatcher) { Rpush::Daemon::Dispatcher::Tcp.new(app, delivery_class, :host => host_proc) }

  before { Rpush::Daemon::TcpConnection.stub(:new => connection) }

  describe 'dispatch' do
    it 'lazily connects the socket' do
      Rpush::Daemon::TcpConnection.should_receive(:new).with(app, host, port).and_return(connection)
      connection.should_receive(:connect)
      dispatcher.dispatch(notification, batch)
    end

    it 'delivers the notification' do
      delivery_class.should_receive(:new).with(app, connection, notification, batch).and_return(delivery)
      delivery.should_receive(:perform)
      dispatcher.dispatch(notification, batch)
    end
  end

  describe 'cleanup' do
    it 'closes the connection' do
      dispatcher.dispatch(notification, batch) # lazily initialize connection
      connection.should_receive(:close)
      dispatcher.cleanup
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rpush-1.0.0-java spec/unit/daemon/dispatcher/tcp_spec.rb
rpush-1.0.0 spec/unit/daemon/dispatcher/tcp_spec.rb