Sha256: d8d907e701206d3d05f0c100786d41597991d0c3d74fd2b65dd44e4e13853dc4

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Isimud::TestClient do
  let(:client) { Isimud::TestClient.new }
  let!(:connection) { client.connect }
  let!(:keys) { %w(foo.bar baz.*.argle) }

  before(:each) do
    @called = false
    @proc = Proc.new { @called = true }
  end

  after(:each) do
    client.close
  end

  describe '#initialize' do
    it 'sets up an empty set of queues' do
      expect( client.queues ).to be_empty
    end
  end

  describe 'queues and bindings' do
    before do
      client.bind('queue_name', 'exchange_name', *keys, &@proc)
    end
    let!(:queue) { client.find_queue('queue_name') }

    it 'binds routing keys to the queue' do
      expect( queue.bindings ).to eql('exchange_name' => Set.new(keys))
    end

    it 'removes a binding from the queue' do
      queue.unbind('exchange_name', routing_key: 'foo.bar')
      expect( queue.bindings ).to eql('exchange_name' => Set.new(['baz.*.argle']))
    end
  end

  describe '#unbind' do
    before do
      client.bind('queue_name', 'exchange_name', *keys, &@proc)
    end
  end

  describe '#publish' do
    before do
      @dont_call = false
      @dont_call_proc = Proc.new { @dont_call = true }
      client.bind('queue_name', 'exchange_name', *keys, &@proc)
      client.bind('other_queue', 'exchange_name', 'no.match.*', &@dont_call_proc)
      client.publish('exchange_name', 'baz.1.argle', {abc: 'do re me'})
    end

    it 'calls proc for the matching queue' do
      expect(@called).to be_truthy
    end

    it 'does not call proc for non matching queue' do
      expect(@dont_call).to be_falsey
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
isimud-1.4.7 spec/isimud/test_client_spec.rb
isimud-1.4.6 spec/isimud/test_client_spec.rb
isimud-1.4.5 spec/isimud/test_client_spec.rb
isimud-1.4.4 spec/isimud/test_client_spec.rb
isimud-1.4.3 spec/isimud/test_client_spec.rb
isimud-1.3.9 spec/isimud/test_client_spec.rb
isimud-1.4.2 spec/isimud/test_client_spec.rb
isimud-1.4.1 spec/isimud/test_client_spec.rb
isimud-1.3.8 spec/isimud/test_client_spec.rb
isimud-1.3.1 spec/isimud/test_client_spec.rb