Sha256: 43d057664bd6be28c616d7d11259e064c332eaa21b8e1091a708d4c2238f473e

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require 'system_metrics/middleware'
require 'system_metrics/collector'

describe SystemMetrics::Middleware do
  before(:each) do
    @store = TestStore.new
    @collector = SystemMetrics::Collector.new(@store)
  end

  it 'should invoke the collector for a non-excluded paths' do
    event = Object.new
    blk = Proc.new { @collector.collect_event(event) }
    middleware = SystemMetrics::Middleware.new(blk, @collector, [])
    env = { "PATH_INFO" => '/collect' }

    middleware.call(env)
    @store.should have(1).events
  end

  it 'should not invoke the collector for excluded paths' do
    event = Object.new
    blk = Proc.new { @collector.collect_event(event) }
    middleware = SystemMetrics::Middleware.new(blk, @collector, [/^\/collect/])
    env = { "PATH_INFO" => '/collect' }

    middleware.call(env)
    @store.should have(0).events
  end

  it 'should wrap everything with an instrumentation for rack requests' do
    ActiveSupport::Notifications.subscribe(/\.rack$/) do |*args|
      @collector.collect_event(ActiveSupport::Notifications::Event.new(*args))
    end

    event = Object.new
    blk = Proc.new {}
    middleware = SystemMetrics::Middleware.new(blk, @collector, [])
    env = { "PATH_INFO" => '/collect' }

    middleware.call(env)
    @store.should have(1).events
    @store.events.first.name.should == 'request.rack'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
system-metrics-0.1.0 spec/system_metrics/middleware_spec.rb