spec/lib/metricize_spec.rb in metricize-0.4.5 vs spec/lib/metricize_spec.rb in metricize-0.4.6

- old
+ new

@@ -1,7 +1,9 @@ require "spec_helper" +class TestError < StandardError; end + describe Metricize do let(:logger) { double.as_null_object } let(:forwarder) { Metricize::Forwarder.new( :password => 'api_key', :username => 'name@example.com', :logger => logger) } @@ -118,10 +120,17 @@ expect(gauges[0]['value']).to eq 20.0 end forwarder.go! end + it "logs in splunk format a sampling of metrics" do + logger.should_receive(:info).with(/prefix_value1=10.0/m).at_least(5).times + 100.times { client.measure('value1', 10) } + logger.should_receive(:info).with(/prefix_value2=20.0/m).at_most(20).times + 100.times { client.measure('value2', 20) } + end + it "raises an error when measure is called without a numeric value" do expect { client.measure('boom', {}) }.to raise_error(ArgumentError, /no numeric value provided in measure call/) expect { client.measure('boom', 'NaN') }.to raise_error(ArgumentError, /no numeric value provided in measure call/) end @@ -232,14 +241,26 @@ expect(first_gauge['value']).to be_within(0.2).of(5000) end forwarder.go! end - it "retries sending if it encounters an error" do + it "rescues and logs redis errors in client" do + Redis.any_instance.stub(:lpush).and_raise(TestError) + logger.should_receive(:error).with(/Client.*TestError/) client.increment('counter1') - RestClient.stub(:post).and_raise(RestClient::Exception) + end + + it "rescues and logs redis errors in forwarder" do + client.increment('counter1') + Redis.any_instance.stub(:lrange).and_raise(TestError) + logger.should_receive(:error).with(/Forwarder.*TestError/) forwarder.go! - RestClient.should_receive(:post) + end + + it "rescues and logs errors when printing histograms" do + 10.times { client.measure('value1', 1.0) } + AsciiCharts::Cartesian.any_instance.stub(:draw).and_raise(TestError) + logger.should_receive(:error).with(/Forwarder.*TestError/) forwarder.go! end end