spec/rollbar_spec.rb in rollbar-2.1.2 vs spec/rollbar_spec.rb in rollbar-2.2.0

- old
+ new

@@ -1560,21 +1560,31 @@ end end end context "send_failsafe" do + let(:exception) { StandardError.new } + it "should not crash when given a message and exception" do - begin - 1 / 0 - rescue => e - notifier.send(:send_failsafe, "test failsafe", e) - end + sent_payload = notifier.send(:send_failsafe, "test failsafe", exception) + + expected_message = 'Failsafe from rollbar-gem: StandardError: test failsafe' + expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message) end it "should not crash when given all nils" do notifier.send(:send_failsafe, nil, nil) end + + context 'without exception object' do + it 'just sends the given message' do + sent_payload = notifier.send(:send_failsafe, "test failsafe", nil) + + expected_message = 'Failsafe from rollbar-gem: test failsafe' + expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message) + end + end end context 'when reporting internal error with nil context' do let(:context_proc) { proc {} } let(:scoped_notifier) { notifier.scope(:context => context_proc) } @@ -1702,18 +1712,23 @@ expect { Rollbar.notifier.process_payload(payload) }.to raise_error(exception) end end end - describe '.process_payload_safely' do + describe '.process_from_async_handler' do context 'with errors' do let(:exception) { StandardError.new('the error') } - it 'doesnt raise anything and sends internal error' do + it 'raises anything and sends internal error' do allow(Rollbar.notifier).to receive(:process_payload).and_raise(exception) expect(Rollbar.notifier).to receive(:report_internal_error).with(exception) - Rollbar.notifier.process_payload_safely({}) + expect do + Rollbar.notifier.process_from_async_handler({}) + end.to raise_error(exception) + + rollbar_do_not_report = exception.instance_variable_get(:@_rollbar_do_not_report) + expect(rollbar_do_not_report).to be_eql(true) end end end describe '#custom_data' do