spec/unit/sidekiq/error_handler_spec.rb in airbrake-5.7.0 vs spec/unit/sidekiq/error_handler_spec.rb in airbrake-5.7.1
- old
+ new
@@ -12,22 +12,37 @@
def wait_for_a_request_with_body(body)
wait_for(a_request(:post, endpoint).with(body: body)).to have_been_made.once
end
- before do
- stub_request(:post, endpoint).to_return(status: 201, body: '{}')
- end
-
- it "sends a notice to Airbrake" do
+ def call_handler
handler = Sidekiq.error_handlers.last
handler.call(
AirbrakeTestError.new('sidekiq error'),
'class' => 'HardSidekiqWorker', 'args' => %w(bango bongo)
)
+ end
+ before do
+ stub_request(:post, endpoint).to_return(status: 201, body: '{}')
+ end
+
+ it "sends a notice to Airbrake" do
+ expect(call_handler).to be_a(Airbrake::Promise)
+
wait_for_a_request_with_body(/"message":"sidekiq\serror"/)
wait_for_a_request_with_body(/"params":{.*"args":\["bango","bongo"\]/)
wait_for_a_request_with_body(/"component":"sidekiq","action":"HardSidekiqWorker"/)
+ end
+
+ context "when Airbrake is not configured" do
+ it "returns nil" do
+ allow(Airbrake).to receive(:build_notice).and_return(nil)
+ allow(Airbrake).to receive(:notify)
+
+ expect(call_handler).to be_nil
+ expect(Airbrake).to have_received(:build_notice)
+ expect(Airbrake).not_to have_received(:notify)
+ end
end
end
end