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
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb