Sha256: 02ccb4905c1b77187df0460163bb1fbbc9717d760b1013ae4a2781f2862d75ec

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

require File.expand_path("../../spec_helper", __FILE__)

module VncTools
  describe ServerPool do
    let(:server) { double(Server, :start => nil, :stop => nil) }
    let(:fake_server_class) { double(:new => server)}
    let(:pool)  { ServerPool.new(3, fake_server_class) }

    it "creates 3 instances of the given display class" do
      fake_server_class.should_receive(:new).exactly(3).times

      pool = ServerPool.new(3, fake_server_class)
      pool.size.should == 3
    end

    it "can fetch a server from the pool" do
      pool.get.should == server
      pool.size.should == 2
    end

    it "can release a server" do
      obj = pool.get
      pool.size.should == 2

      pool.release obj
    end

    it "can stop the pool" do
      pool.stub(:running => [server])
      server.should_receive(:stop)

      pool.stop
    end

    it "raises a TooManyDisplaysError if the pool is over capacity" do
      lambda { pool.release "foo" }.should raise_error(ServerPool::TooManyDisplaysError)
    end

    it "raises a OutOfDisplaysError if the pool is empty" do
      3.times { pool.get }
      lambda { pool.get }.should raise_error(ServerPool::OutOfDisplaysError)
    end

    it "notifies observers" do
      observer = double(Observable)

      observer.should_receive(:update).with :on_display_starting, server
      observer.should_receive(:update).with :on_display_fetched , server
      observer.should_receive(:update).with :on_display_released, server
      observer.should_receive(:update).with :on_display_stopping , server

      pool.add_observer observer

      pool.release pool.get
      pool.stop
    end

  end # ServerPool
end # VncTools

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vnctools-0.0.9 spec/vnctools/server_pool_spec.rb
vnctools-0.0.9.pre1 spec/vnctools/server_pool_spec.rb
vnctools-0.0.8 spec/vnctools/server_pool_spec.rb