Sha256: 943473b1be4f7654f6f123818461344a97a3e7861a8dab95ab0101156ea5bee0

Contents?: true

Size: 1.53 KB

Versions: 167

Compression:

Stored size: 1.53 KB

Contents

require 'rack/lint'
require 'rack/mock'
require 'rack/runtime'

describe Rack::Runtime do
  def runtime_app(app, *args)
    Rack::Lint.new Rack::Runtime.new(app, *args)
  end
  
  def request
    Rack::MockRequest.env_for
  end
  
  it "sets X-Runtime is none is set" do
    app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
    response = runtime_app(app).call(request)
    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 = runtime_app(app).call(request)
    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 = runtime_app(app, "Test").call(request)
    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 = runtime_app(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(request)

    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

167 entries across 145 versions & 41 rubygems

Version Path
rack-1.6.2 test/spec_runtime.rb
rack-1.5.4 test/spec_runtime.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/rack-1.6.0/test/spec_runtime.rb
rack-1.5.3 test/spec_runtime.rb
rack-1.6.1 test/spec_runtime.rb
rack-1.6.0 test/spec_runtime.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rack-1.4.5/test/spec_runtime.rb
rack-1.6.0.beta2 test/spec_runtime.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_runtime.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/test/spec_runtime.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_runtime.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_runtime.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/test/spec_runtime.rb
rack-1.6.0.beta test/spec_runtime.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/test/spec_runtime.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rack-1.5.2/test/spec_runtime.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_runtime.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rack-1.5.2/test/spec_runtime.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_runtime.rb
challah-1.0.0 vendor/bundle/gems/rack-1.5.2/test/spec_runtime.rb