spec/sidekiq/middleware/server/datadog_spec.rb in sidekiq-datadog-0.5.3 vs spec/sidekiq/middleware/server/datadog_spec.rb in sidekiq-datadog-0.6.0

- old
+ new

@@ -1,8 +1,9 @@ require 'spec_helper' describe Sidekiq::Middleware::Server::Datadog do + subject { described_class.new(hostname: 'test.host', statsd: statsd, tags: tags, **options) } let(:statsd) { Mock::Statsd.new('localhost', 55555) } let(:worker) { Mock::Worker.new } let(:tags) do ['custom:tag', ->(w, *) { "worker:#{w.class.name[1..2]}" }] @@ -21,13 +22,11 @@ end Timecop.freeze(Time.at(enqueued_at + expected_queued_time_ms.to_f / 1000)) end - subject { described_class.new(hostname: 'test.host', statsd: statsd, tags: tags, **options) } - - it 'should send an increment and timing event for each job run' do + it 'sends an increment and timing event for each job run' do subject.call(worker, { 'enqueued_at' => enqueued_at }, 'default') { 'ok' } expect(statsd.messages).to eq([ 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\ 'queue:default,status:ok', 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:mock/worker,'\ @@ -35,21 +34,21 @@ "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#custom:tag,worker:oc,host:test.host,"\ 'env:test,name:mock/worker,queue:default,status:ok', ]) end - it 'should support wrappers' do + it 'supports wrappers' do subject.call(worker, { 'enqueued_at' => enqueued_at, 'wrapped' => 'wrap' }, nil) { 'ok' } expect(statsd.messages).to eq([ 'sidekiq.job:1|c|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok', 'sidekiq.job.time:333|ms|#custom:tag,worker:oc,host:test.host,env:test,name:wrap,status:ok', "sidekiq.job.queued_time:#{expected_queued_time_ms}|ms|#custom:tag,worker:oc,host:test.host,"\ 'env:test,name:wrap,status:ok', ]) end - it 'should handle errors' do + it 'handles errors' do expect(lambda { subject.call(worker, {}, nil) { raise 'doh!' } }).to raise_error('doh!') expect(statsd.messages).to eq([ @@ -63,11 +62,11 @@ context 'with a dynamic tag list' do let(:tags) do ['custom:tag', ->(_w, j, *) { j['args'].map {|n| "arg:#{n}" } }] end - it 'should generate the correct tags' do + it 'generates the correct tags' do subject.call(worker, { 'enqueued_at' => enqueued_at, 'args' => [1, 2] }, 'default') { 'ok' } expect(statsd.messages).to eq([ 'sidekiq.job:1|c|#custom:tag,arg:1,arg:2,host:test.host,env:test,name:mock/worker,'\ 'queue:default,status:ok', @@ -81,11 +80,11 @@ context 'with a list of skipped tags' do let(:tags) { [] } let(:options) { { skip_tags: %i[env host name] } } - it 'should send metrics without the skipped tags' do + it 'sends metrics without the skipped tags' do subject.call(worker, { 'enqueued_at' => 1461881794.9312189 }, 'default') { 'ok' } expect(statsd.messages).to eq([ 'sidekiq.job:1|c|#queue:default,status:ok', 'sidekiq.job.time:333|ms|#queue:default,status:ok', @@ -97,10 +96,10 @@ context 'when sidekiq/api is required' do before do require 'sidekiq/api' end - it 'should not raise any errors' do + it 'does not raise any errors' do expect do subject.call(worker, { 'enqueued_at' => enqueued_at }, 'default') { 'ok' } end.not_to raise_error end end