summaryrefslogtreecommitdiff
path: root/test/spec_runtime.rb
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2010-06-15 11:37:52 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2010-06-15 11:37:52 +0200
commite617e8f67bcbcff6b5fcb1670747bc020b869b72 (patch)
tree50b74613b03f57c2a8d757c6402ed8f5f144c752 /test/spec_runtime.rb
parent19c8aee05c2cbb4441017c751b2ff27fa3ca1cff (diff)
downloadrack-e617e8f67bcbcff6b5fcb1670747bc020b869b72.tar.gz
Rename spec/ back to test/
Diffstat (limited to 'test/spec_runtime.rb')
-rw-r--r--test/spec_runtime.rb39
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