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.1.9 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/rack-1.6.5/test/spec_runtime.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/rack-1.6.5/test/spec_runtime.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/rack-1.6.6/test/spec_runtime.rb
rack-1.6.13 test/spec_runtime.rb
rack-1.6.12 test/spec_runtime.rb
rack-1.6.11 test/spec_runtime.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/rack-1.6.6/test/spec_runtime.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/rack-1.6.10/test/spec_runtime.rb
rack-1.6.10 test/spec_runtime.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rack-1.6.8/test/spec_runtime.rb