Sha256: 82a1a689214af26235e3c9e8fe77050783200b32817e34c21379ac012e4b3833

Contents?: true

Size: 1.56 KB

Versions: 55

Compression:

Stored size: 1.56 KB

Contents

require 'minitest/autorun'
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'].must_match(/[\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'].must_equal "foobar"
  end

  it "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'].must_match(/[\d\.]+/)
  end

  it "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'].must_match(/[\d\.]+/)
    response[1]['X-Runtime-All'].must_match(/[\d\.]+/)

    Float(response[1]['X-Runtime-All']).must_be :>, Float(response[1]['X-Runtime-App'])
  end
end

Version data entries

55 entries across 53 versions & 14 rubygems

Version Path
rack-2.0.9.4 test/spec_runtime.rb
rack-2.0.9.3 test/spec_runtime.rb
rack-2.0.9.2 test/spec_runtime.rb
rack-2.0.9.1 test/spec_runtime.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-2.0.5/test/spec_runtime.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/test/spec_runtime.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/test/spec_runtime.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
rack-2.0.9 test/spec_runtime.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-2.0.8/test/spec_runtime.rb
rack-2.0.8 test/spec_runtime.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
tdiary-5.1.0 vendor/bundle/gems/rack-2.0.7/test/spec_runtime.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_runtime.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/test/spec_runtime.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/rack-2.0.7/test/spec_runtime.rb