From fa8a8fc57af80c1ac407eff16d2e10f3329ac301 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 3 Feb 2012 15:29:50 +0000 Subject: [PATCH] use Configuration#bucket instead of hard-coded bucket value, and some spec cleanup --- lib/airbrake-statsd.rb | 2 +- spec/unit/airbrake-statsd_spec.rb | 52 ++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/lib/airbrake-statsd.rb b/lib/airbrake-statsd.rb index 3ca9a0e..2e558ca 100644 --- a/lib/airbrake-statsd.rb +++ b/lib/airbrake-statsd.rb @@ -32,7 +32,7 @@ module Airbrake def increment return unless configured? - client.increment('exceptions') + client.increment(config.bucket) end end # << self diff --git a/spec/unit/airbrake-statsd_spec.rb b/spec/unit/airbrake-statsd_spec.rb index 450fcb1..ae5c4c9 100644 --- a/spec/unit/airbrake-statsd_spec.rb +++ b/spec/unit/airbrake-statsd_spec.rb @@ -6,11 +6,26 @@ module Airbrake subject { Statsd } before do - subject.instance_variable_set('@configured', nil) - subject.instance_variable_set('@config', nil) - subject.instance_variable_set('@client', nil) + ['@configured', '@config', '@client'].each do |var_name| + subject.instance_variable_set(var_name, nil) + end end + describe '#configure' do + it 'sets @configured to true' do + subject.instance_variable_get('@configured').should_not be_true + subject.configure + subject.instance_variable_get('@configured').should be_true + end + + context 'when block is passed' do + it 'passes #config to block' do + block = Proc.new { |conf| conf.should be_a(Statsd::Configuration) } + subject.configure(&block) + end + end # block passed + end # configure + describe '#configured?' do context 'when #configure has been called' do it 'returns true' do @@ -30,7 +45,7 @@ module Airbrake it 'creates new Configuration instance if not set' do subject.config.should be_a(Statsd::Configuration) end - end + end # config describe '#client' do it 'creates a new ::Statsd client instance if not set' do @@ -49,23 +64,36 @@ module Airbrake ::Statsd.any_instance.should_receive(:namespace=).with('test').once subject.client end - end - end + end # namespace is set + end # client describe '#increment' do context 'when #configure has been called' do before { subject.configure } - it 'calls #increment on #client instance' do - subject.client.should_receive(:increment).once - subject.increment - end - - it 'default bucket name used is "exceptions"' do + it 'calls #increment on #client' do subject.client.should_receive(:increment).with('exceptions').once subject.increment end + + context 'when bucket option has been customized' do + before do + subject.configure { |config| config.bucket = 'errors' } + end + + it 'calls #increment on #client with custom bucket' do + subject.client.should_receive(:increment).with('errors').once + subject.increment + end + end # bucket option customized end # configure called + + context 'when #configure has not been called' do + it 'does not call #increment on #client' do + subject.client.should_not_receive(:increment) + subject.increment + end + end # configure not called end # increment end