File: spec_rack_lock.rb

package info (click to toggle)
librack-ruby 1.1.0-4%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 3,204 kB
  • ctags: 1,101
  • sloc: ruby: 8,704; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 925 bytes parent folder | download | duplicates (2)
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
require 'test/spec'

require 'rack/mock'
require 'rack/lock'

context "Rack::Lock" do
  class Lock
    attr_reader :synchronized

    def initialize
      @synchronized = false
    end

    def synchronize
      @synchronized = true
      yield
    end
  end

  specify "should call synchronize on lock" do
    lock = Lock.new
    env = Rack::MockRequest.env_for("/")
    app = Rack::Lock.new(lambda { |env| }, lock)
    lock.synchronized.should.equal false
    app.call(env)
    lock.synchronized.should.equal true
  end

  specify "should set multithread flag to false" do
    app = Rack::Lock.new(lambda { |env| env['rack.multithread'] })
    app.call(Rack::MockRequest.env_for("/")).should.equal false
  end

  specify "should reset original multithread flag when exiting lock" do
    app = Rack::Lock.new(lambda { |env| env })
    app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true
  end
end