Sha256: 672ac131023323d2d9bd1d348329973ffe0c463ab65cee539f1da3a04e28a3ac

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class HelpersTest < Minitest::Test
  def setup
    test_class = Class.new(Minitest::Test)
    test_class.send(:include, StatsD::Instrument::Helpers)
    @test_case = test_class.new('fake')
  end

  def test_capture_metrics_inside_block_only
    StatsD.increment('counter')
    metrics = @test_case.capture_statsd_calls do
      StatsD.increment('counter')
      StatsD.gauge('gauge', 12)
    end
    StatsD.gauge('gauge', 15)

    assert_equal(2, metrics.length)
    assert_equal('counter', metrics[0].name)
    assert_equal('gauge', metrics[1].name)
    assert_equal(12, metrics[1].value)
  end

  def test_capture_metrics_with_new_client
    @old_client = StatsD.singleton_client
    StatsD.singleton_client = StatsD::Instrument::Client.new

    StatsD.increment('counter')
    metrics = @test_case.capture_statsd_datagrams do
      StatsD.increment('counter')
      StatsD.gauge('gauge', 12)
    end
    StatsD.gauge('gauge', 15)

    assert_equal(2, metrics.length)

  ensure
    StatsD.singleton_client = @old_client
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
statsd-instrument-3.0.2 test/helpers_test.rb
statsd-instrument-3.0.1 test/helpers_test.rb