Sha256: d547f9353186a5fa4e84e6a4fc252f0e079890b150909cb51e4a149cd0f05804

Contents?: true

Size: 1.36 KB

Versions: 149

Compression:

Stored size: 1.36 KB

Contents

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

Version data entries

149 entries across 128 versions & 16 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
classiccms-0.7.4 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
classiccms-0.7.3 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
candlepin-api-0.4.0 bundle/ruby/gems/rack-1.3.5/test/spec_runtime.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/test/spec_runtime.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rack-1.3.5/test/spec_runtime.rb
classiccms-0.7.2 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
classiccms-0.7.1 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
classiccms-0.7.0 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
rack-1.3.10 test/spec_runtime.rb
rack-1.2.8 test/spec_runtime.rb
rack-1.3.9 test/spec_runtime.rb
rack-1.2.7 test/spec_runtime.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_runtime.rb
rack-1.3.8 test/spec_runtime.rb
rack-1.3.7 test/spec_runtime.rb
rack-1.2.6 test/spec_runtime.rb
challah-0.9.0 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
classiccms-0.6.9 vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_runtime.rb