1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
# frozen_string_literal: true
require 'spec_helper'
class Bugsnag
# mock Bugsnag
end
RSpec.describe UniformNotifier::BugsnagNotifier do
let(:notification_data) { {} }
let(:report) { double('Bugsnag::Report') }
before do
allow(report).to receive(:severity=)
allow(report).to receive(:add_tab)
allow(report).to receive(:grouping_hash=)
end
it 'should not notify bugsnag' do
expect(Bugsnag).not_to receive(:notify)
UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
end
context 'with string notification' do
let(:notification_data) { 'notify bugsnag' }
it 'should notify bugsnag' do
expect(Bugsnag).to receive(:notify).with(
UniformNotifier::Exception.new(notification_data)
).and_yield(report)
expect(report).to receive(:severity=).with('warning')
expect(report).to receive(:add_tab).with(:bullet, { title: notification_data })
expect(report).to receive(:grouping_hash=).with(notification_data)
UniformNotifier.bugsnag = true
UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
end
it 'should notify bugsnag with additional report configuration' do
expect(Bugsnag).to receive(:notify).with(
UniformNotifier::Exception.new(notification_data)
).and_yield(report)
expect(report).to receive(:meta_data=).with({ foo: :bar })
UniformNotifier.bugsnag = ->(report) { report.meta_data = { foo: :bar } }
UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
end
end
context 'with hash notification' do
let(:notification_data) { { user: 'user', title: 'notify bugsnag', url: 'URL', body: 'something' } }
it 'should notify bugsnag' do
expect(Bugsnag).to receive(:notify).with(
UniformNotifier::Exception.new(notification_data[:title])
).and_yield(report)
expect(report).to receive(:severity=).with('warning')
expect(report).to receive(:add_tab).with(:bullet, notification_data)
expect(report).to receive(:grouping_hash=).with(notification_data[:body])
UniformNotifier.bugsnag = true
UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
end
it 'should notify bugsnag with option' do
expect(Bugsnag).to receive(:notify).with(
UniformNotifier::Exception.new(notification_data[:title])
).and_yield(report)
expect(report).to receive(:meta_data=).with({ foo: :bar })
UniformNotifier.bugsnag = ->(report) { report.meta_data = { foo: :bar } }
UniformNotifier::BugsnagNotifier.out_of_channel_notify(notification_data)
end
end
it 'should notify bugsnag with correct backtrace' do
expect(Bugsnag).to receive(:notify) do |error|
expect(error).to be_a UniformNotifier::Exception
expect(error.backtrace).to eq ['bugsnag spec test']
end
UniformNotifier.bugsnag = true
UniformNotifier::BugsnagNotifier.out_of_channel_notify(backtrace: ['bugsnag spec test'])
end
end
|