Sha256: daa7852dad51da4d29c5b7c367ad4330faba537cfccaf5e450b33bfbd61ce2a1

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

# -*- encoding: utf-8 -*-
require 'spec_helper'

module OnStomp::Failover::Pools
  describe Base, :failover => true do
    let(:clients) { mock('clients') }
    let(:pool) {
      Base.new([]).tap do |p|
        p.stub(:clients => clients)
      end
    }

    describe ".initialize" do
      it "should create a new Client for each URI" do
        OnStomp::Client.should_receive(:new).with('1').and_return('c 1')
        OnStomp::Client.should_receive(:new).with('2').and_return('c 2')
        OnStomp::Client.should_receive(:new).with('3').and_return('c 3')
        new_pool = Base.new ['1', '2', '3']
        new_pool.clients.should =~ ['c 1', 'c 2', 'c 3']
      end
    end
    
    describe ".shuffle!" do
      it "should shuffle the clients" do
        clients.should_receive(:shuffle!)
        pool.shuffle!
      end
    end
    
    describe ".next_client" do
      it "should raise an error because it's up to subclasses to implement this warlock" do
        lambda {
          pool.next_client
        }.should raise_error
      end
    end
    
    describe ".each" do
      it "should raise an error if no block is given (not sure why, honestly)" do
        # I think in the past, this method was synchronized, and that's why
        # I raise an error, but it may not be necessary anymore
        lambda {
          pool.each
        }.should raise_error
      end
      it "should evaluate the block against the clients" do
        clients.should_receive(:each).and_yield('c1')
        yielded = []
        pool.each { |c| yielded << c }
        yielded.should == ['c1']
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
onstomp-1.0.8 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.7 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.6 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.5 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.4 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.3 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.2 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.1 spec/onstomp/failover/pools/base_spec.rb
onstomp-1.0.0 spec/onstomp/failover/pools/base_spec.rb