Sha256: 667fe81f7b7bde8074f6eaf4d7fde307d20b0a2f8b9faa5d11953333577252b9

Contents?: true

Size: 1.37 KB

Versions: 19

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'
require 'napa/stats'

describe Napa::Stats do
  before do
    # Delete any prevous instantiations of the emitter
    Napa::Stats.emitter = nil
    # Stub out logging since there is no log to output to
    Napa::Logger.stub_chain(:logger, :warn)
  end

  it 'should log an error if StatsD env variables are not configured' do
    ENV['STATSD_HOST'] = nil
    ENV['STATSD_PORT'] = nil
    message = 'StatsD host and port not configured in environment variables, using default settings'
    Napa::Logger.logger.should_receive(:warn).with(message)
    Napa::Stats.emitter
  end

  it 'should default statsd to localhost port 8125 if env vars are not specified' do
    ENV['STATSD_HOST'] = nil
    ENV['STATSD_PORT'] = nil
    expect(Napa::Stats.emitter.host).to eq('127.0.0.1')
    expect(Napa::Stats.emitter.port).to eq(8125)
  end

  it 'should return a StatsD client object' do
    expect(Napa::Stats.emitter.class.name).to eq('Statsd')
  end

  it 'the namespace of the StatsD client object should equal the service name' do
    ENV['SERVICE_NAME'] = 'my-service'
    expect(Napa::Stats.emitter.namespace).to eq('my-service')
  end

  it 'should use env variables to set statsd host and port' do
    ENV['STATSD_HOST']  = 'localhost'
    ENV['STATSD_PORT']  = '9000'
    expect(Napa::Stats.emitter.host).to eq('localhost')
    expect(Napa::Stats.emitter.port).to eq('9000')
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
napa-0.2.1 spec/stats_spec.rb
napa-0.2.0 spec/stats_spec.rb
napa-0.1.29 spec/stats_spec.rb
napa-0.1.28 spec/stats_spec.rb
napa-0.1.26 spec/stats_spec.rb
napa-0.1.25 spec/stats_spec.rb
napa-0.1.24 spec/stats_spec.rb
napa-0.1.23 spec/stats_spec.rb
napa-0.1.22 spec/stats_spec.rb
napa-0.1.21 spec/stats_spec.rb
napa-0.1.20 spec/stats_spec.rb
napa-0.1.19 spec/stats_spec.rb
napa-0.1.18 spec/stats_spec.rb
napa-0.1.17 spec/stats_spec.rb
napa-0.1.16 spec/stats_spec.rb
napa-0.1.15 spec/stats_spec.rb
napa-0.1.14 spec/stats_spec.rb
napa-0.1.12 spec/stats_spec.rb
napa-0.1.13 spec/stats_spec.rb