Sha256: d0f8deefabf1b521a753348ec13c425c861e29b936d0419eb9ade6c1855a1e26

Contents?: true

Size: 1.62 KB

Versions: 7

Compression:

Stored size: 1.62 KB

Contents

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

module VncTools
  describe ServerPool do
    let(:server) { mock(Server, :start => nil, :stop => nil) }
    let(:fake_server_class) { mock(: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 = mock(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

7 entries across 7 versions & 1 rubygems

Version Path
vnctools-0.0.7 spec/vnctools/server_pool_spec.rb
vnctools-0.0.6 spec/vnctools/server_pool_spec.rb
vnctools-0.0.5 spec/vnctools/server_pool_spec.rb
vnctools-0.0.4 spec/vnctools/server_pool_spec.rb
vnctools-0.0.3 spec/vnctools/server_pool_spec.rb
vnctools-0.0.2 spec/vnctools/server_pool_spec.rb
vnctools-0.0.1 spec/vnctools/server_pool_spec.rb