Sha256: 1ef44f4abb9e923a2ed6eb96dfbd55583599e9acb6f7330632ca96306ac5e5c6

Contents?: true

Size: 1.38 KB

Versions: 23

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

class FasterApp
  def self.call(env)
    sleep 0.05; [200, {}, "50ms"]
  end
end

class SlowerApp
  def self.call(env)
    sleep 0.2; [200, {}, "200ms"]
  end
end

describe RightSupport::Rack::Runtime do
  before(:each) do
    @app = flexmock('Rack app')
    @app.should_receive(:call).and_return([200, {}, 'body']).by_default
    @env = {'rack.logger' => @logger}
    @middleware = RightSupport::Rack::Runtime.new(@app)
  end

  context :call do
    it 'sets an X-Runtime header in response' do
      @middleware.call(@env).should == [200, {"X-Runtime"=>"0"}, 'body']
    end

    it 'sets a correct X-Runtime value for 50 ms app' do
      faster = RightSupport::Rack::Runtime.new(FasterApp)
      result = faster.call(@env)
      result[1].keys.should == ['X-Runtime']
      result[1]['X-Runtime'].to_i.should >= 50
      result[1]['X-Runtime'].to_i.should < 70
    end

    it 'sets a correct X-Runtime value for 200 ms app' do
      slower = RightSupport::Rack::Runtime.new(SlowerApp)
      result = slower.call(@env)
      result[1].keys.should == ['X-Runtime']
      result[1]['X-Runtime'].to_i.should >= 200
      result[1]['X-Runtime'].to_i.should < 270
    end

    it 'allows appending custom name to X-Runtime header' do
      customized = RightSupport::Rack::Runtime.new(@app, "Test")
      customized.call(@env).should == [200, {"X-Runtime-Test"=>"0"}, 'body']
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
right_support-2.11.3 spec/rack/runtime_spec.rb
right_support-2.11.2 spec/rack/runtime_spec.rb
right_support-2.10.1 spec/rack/runtime_spec.rb
right_support-2.9.6 spec/rack/runtime_spec.rb
right_support-2.9.5 spec/rack/runtime_spec.rb
right_support-2.9.4 spec/rack/runtime_spec.rb
right_support-2.9.3 spec/rack/runtime_spec.rb
right_support-2.9.2 spec/rack/runtime_spec.rb
right_support-2.9.1 spec/rack/runtime_spec.rb
right_support-2.8.46 spec/rack/runtime_spec.rb
right_support-2.8.45 spec/rack/runtime_spec.rb
right_support-2.8.44 spec/rack/runtime_spec.rb
right_support-2.8.43 spec/rack/runtime_spec.rb
right_support-2.8.42 spec/rack/runtime_spec.rb
right_support-2.8.41 spec/rack/runtime_spec.rb
right_support-2.8.40 spec/rack/runtime_spec.rb
right_support-2.8.39 spec/rack/runtime_spec.rb
right_support-2.8.38 spec/rack/runtime_spec.rb
right_support-2.8.37 spec/rack/runtime_spec.rb
right_support-2.8.36 spec/rack/runtime_spec.rb