diff options
author | Christian Neukirchen <chneukirchen@gmail.com> | 2010-06-15 11:37:52 +0200 |
---|---|---|
committer | Christian Neukirchen <chneukirchen@gmail.com> | 2010-06-15 11:37:52 +0200 |
commit | e617e8f67bcbcff6b5fcb1670747bc020b869b72 (patch) | |
tree | 50b74613b03f57c2a8d757c6402ed8f5f144c752 /test/spec_runtime.rb | |
parent | 19c8aee05c2cbb4441017c751b2ff27fa3ca1cff (diff) | |
download | rack-e617e8f67bcbcff6b5fcb1670747bc020b869b72.tar.gz |
Rename spec/ back to test/
Diffstat (limited to 'test/spec_runtime.rb')
-rw-r--r-- | test/spec_runtime.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/spec_runtime.rb b/test/spec_runtime.rb new file mode 100644 index 00000000..547a32ec --- /dev/null +++ b/test/spec_runtime.rb @@ -0,0 +1,39 @@ +require 'rack/runtime' + +describe Rack::Runtime do + it "sets X-Runtime is none is set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::Runtime.new(app).call({}) + response[1]['X-Runtime'].should =~ /[\d\.]+/ + end + + it "doesn't set the X-Runtime if it is already set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain', "X-Runtime" => "foobar"}, "Hello, World!"] } + response = Rack::Runtime.new(app).call({}) + response[1]['X-Runtime'].should == "foobar" + end + + should "allow a suffix to be set" do + app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + response = Rack::Runtime.new(app, "Test").call({}) + response[1]['X-Runtime-Test'].should =~ /[\d\.]+/ + end + + should "allow multiple timers to be set" do + app = lambda { |env| sleep 0.1; [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } + runtime = Rack::Runtime.new(app, "App") + + # wrap many times to guarantee a measurable difference + 100.times do |i| + runtime = Rack::Runtime.new(runtime, i.to_s) + end + runtime = Rack::Runtime.new(runtime, "All") + + response = runtime.call({}) + + response[1]['X-Runtime-App'].should =~ /[\d\.]+/ + response[1]['X-Runtime-All'].should =~ /[\d\.]+/ + + Float(response[1]['X-Runtime-All']).should > Float(response[1]['X-Runtime-App']) + end +end |