rtomayko / rack-cache

Real HTTP Caching for Ruby Web Apps

This URL has Read+Write access

rtomayko (author)
Sat Jun 06 02:04:44 -0700 2009
commit  12b0de7eaa4801c97a57e6fb3c4bcf2d84056f64
tree    4c27052373f4d84e265be409be3159c937c9f396
parent  05d23360c3e08ccb2bc5af5fae060c34cfceeeb2
rack-cache / test / cache_test.rb
100644 39 lines (32 sloc) 1.035 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
require "#{File.dirname(__FILE__)}/spec_setup"
 
def dumb_app(env)
  body = block_given? ? [yield] : ['Hi']
  [ 200, {'Content-Type' => 'text/plain'}, body ]
end
 
describe 'Rack::Cache::new' do
  before { @app = method(:dumb_app) }
 
  it 'takes a backend and returns a middleware component' do
    Rack::Cache.new(@app).
      should.respond_to :call
  end
 
  it 'takes an options Hash' do
    lambda { Rack::Cache.new(@app, {}) }.
      should.not.raise(ArgumentError)
  end
 
  it 'sets options provided in the options Hash' do
    object = Rack::Cache.new(@app, :foo => 'bar', 'foo.bar' => 'bling')
    object.options['foo.bar'].should.equal 'bling'
    object.options['rack-cache.foo'].should.equal 'bar'
  end
 
  it 'takes a block; executes it during initialization' do
    state, object = 'not invoked', nil
    instance =
      Rack::Cache.new @app do |cache|
        object = cache
        state = 'invoked'
        cache.should.respond_to :set
      end
    state.should.equal 'invoked'
    object.should.be instance
  end
end