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
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/rack-1.6.4/test/spec_runtime.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_runtime.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_runtime.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/rack-1.6.4/test/spec_runtime.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/rack-1.6.4/test/spec_runtime.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/test/spec_runtime.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/rack-1.6.4/test/spec_runtime.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/rack-1.5.5/test/spec_runtime.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/test/spec_runtime.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rack-1.6.4/test/spec_runtime.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rack-1.6.4/test/spec_runtime.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rack-1.6.1/test/spec_runtime.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rack-1.6.4/test/spec_runtime.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rack-1.6.2/test/spec_runtime.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_runtime.rb
rack-1.6.4 test/spec_runtime.rb
rack-1.4.7 test/spec_runtime.rb
rack-1.5.5 test/spec_runtime.rb
rack-1.6.3 test/spec_runtime.rb
rack-1.4.6 test/spec_runtime.rb