require File.dirname(__FILE__) + '/../spec_helper' describe FastCache::Memcache::Node, 'initialize' do before :each do @node = FastCache::Memcache::Node.new('localhost', 11211) end it 'should take host and port as arguments' do @node.host.should == 'localhost' @node.port.should == 11211 end it 'should set a default weight of 1' do @node.weight.should == 1 end it 'should set a default status of disconnected' do @node.status.should == :disconnected end end describe FastCache::Memcache::Node, 'connect' do before :each do @conn = FastCache::Memcache::Node.new('localhost', 11211) end describe '(success)' do it 'should set the status to :connected' do TCPSocket.should_receive(:new).with(@conn.host, @conn.port) @conn.connect @conn.status.should == :connected end end describe '(failure)' do it 'should set the status to :dead' do TCPSocket.should_receive(:new).with(@conn.host, @conn.port).and_raise(Errno::ECONNREFUSED) @conn.connect @conn.status.should == :dead end end end