File: cache_test.rb

package info (click to toggle)
ruby-rack-cache 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: ruby: 3,581; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 960 bytes parent folder | download
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
require_relative 'test_helper'

describe Rack::Cache do
  def dumb_app(_env)
    body = block_given? ? [yield] : ['Hi']
    [ 200, {'content-type' => 'text/plain'}, body ]
  end

  before { @app = method(:dumb_app) }

  it 'takes a backend and returns a middleware component' do
    assert Rack::Cache.new(@app).respond_to? :call
  end

  it 'takes an options Hash' do
    Rack::Cache.new(@app, {})
  end

  it 'sets options provided in the options Hash' do
    object = Rack::Cache.new(@app, :foo => 'bar', 'foo.bar' => 'bling')
    object.options['foo.bar'].must_equal 'bling'
    object.options['rack-cache.foo'].must_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'
        assert cache.respond_to? :set
      end
    state.must_equal 'invoked'
    object.must_equal instance
  end
end