public
Description: self assembling fabric of ruby daemons
Homepage:
Clone URL: git://github.com/ezmobius/nanite.git
nanite / spec / certificate_cache_spec.rb
100644 49 lines (38 sloc) 1.111 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require File.join(File.dirname(__FILE__), 'spec_helper')
 
describe Nanite::CertificateCache do
 
  before(:each) do
    @cache = Nanite::CertificateCache.new(2)
  end
 
  it 'should allow storing and retrieving objects' do
    @cache['some_id'].should be_nil
    @cache['some_id'] = 'some_value'
    @cache['some_id'].should == 'some_value'
  end
 
  it 'should not store more than required' do
    @cache[1] = 'oldest'
    @cache[2] = 'older'
    @cache[1].should == 'oldest'
    @cache[2].should == 'older'
  
    @cache[3] = 'new'
    @cache[3].should == 'new'
 
    @cache[1].should be_nil
    @cache[2].should == 'older'
  end
 
  it 'should use LRU to remove entries' do
    @cache[1] = 'oldest'
    @cache[2] = 'older'
    @cache[1].should == 'oldest'
    @cache[2].should == 'older'
  
    @cache[1] = 'new'
    @cache[3] = 'newer'
    @cache[1].should == 'new'
    @cache[3].should == 'newer'
 
    @cache[2].should be_nil
  end
 
  it 'should store items returned by block' do
    @cache[1].should be_nil
    item = @cache.get(1) { 'item' }
    item.should == 'item'
    @cache[1].should == 'item'
  end
 
end