cache_test.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require "#{File.dirname(__FILE__)}/spec_setup"
  2. def dumb_app(env)
  3. body = block_given? ? [yield] : ['Hi']
  4. [ 200, {'Content-Type' => 'text/plain'}, body ]
  5. end
  6. describe 'Rack::Cache::new' do
  7. before { @app = method(:dumb_app) }
  8. it 'takes a backend and returns a middleware component' do
  9. Rack::Cache.new(@app).
  10. should.respond_to :call
  11. end
  12. it 'takes an options Hash' do
  13. lambda { Rack::Cache.new(@app, {}) }.
  14. should.not.raise(ArgumentError)
  15. end
  16. it 'sets options provided in the options Hash' do
  17. object = Rack::Cache.new(@app, :foo => 'bar', 'foo.bar' => 'bling')
  18. object.options['foo.bar'].should.equal 'bling'
  19. object.options['rack-cache.foo'].should.equal 'bar'
  20. end
  21. it 'takes a block; executes it during initialization' do
  22. state, object = 'not invoked', nil
  23. instance =
  24. Rack::Cache.new @app do |cache|
  25. object = cache
  26. state = 'invoked'
  27. cache.should.respond_to :set
  28. end
  29. state.should.equal 'invoked'
  30. object.should.be.same_as instance
  31. end
  32. end