spec/sidekiq/statsd/server_middleware_spec.rb in sidekiq-statsd-0.1.5 vs spec/sidekiq/statsd/server_middleware_spec.rb in sidekiq-statsd-1.0.0

- old
+ new

@@ -12,11 +12,11 @@ let(:clean_job) { ->{} } let(:broken_job) { ->{ raise 'error' } } before do - ::Statsd.stub_chain(:new, :batch).and_yield(client) + allow_any_instance_of(::Statsd).to receive(:batch).and_yield(client) end it "doesn't initialize a ::Statsd client if passed-in" do expect(::Statsd) .to receive(:new) @@ -37,12 +37,13 @@ end it "uses the custom metric name prefix options" do expect(client) .to receive(:time) - .with("development.application.sidekiq.#{worker_name}.processing_time", &clean_job) + .with("development.application.sidekiq.#{worker_name}.processing_time") .once + .and_yield described_class .new(env: 'development', prefix: 'application.sidekiq') .call(worker, msg, queue, &clean_job) end @@ -57,11 +58,11 @@ expect(described_class.new(sidekiq_stats: false).instance_variable_get(:@sidekiq_stats)) .to be_nil end it "doesn't gauge sidekiq stats" do - Sidekiq::Stats.stub(:new).and_return(sidekiq_stats) + allow(Sidekiq::Stats).to receive(:new) { sidekiq_stats } expect(sidekiq_stats).not_to receive(:enqueued) expect(sidekiq_stats).not_to receive(:retry_size) expect(sidekiq_stats).not_to receive(:processed) expect(sidekiq_stats).not_to receive(:failed) @@ -86,12 +87,13 @@ end it "times the process execution" do expect(client) .to receive(:time) - .with("production.worker.#{worker_name}.processing_time", &job) + .with("production.worker.#{worker_name}.processing_time") .once + .and_yield middleware.call(worker, msg, queue, &job) end end @@ -103,19 +105,20 @@ describe "#call" do before do allow(client) .to receive(:time) - .with("production.worker.#{worker_name}.processing_time", &job) + .with("production.worker.#{worker_name}.processing_time") + .and_yield end it "increments failure counter" do expect(client) .to receive(:increment) .with("production.worker.#{worker_name}.failure") .once - expect{ middleware.call(worker, msg, queue, &job) }.to raise_error + expect{ middleware.call(worker, msg, queue, &job) }.to raise_error('error') end end it_behaves_like "a resilient gauge reporter" end