|
18 | 18 | end)
|
19 | 19 | end
|
20 | 20 |
|
| 21 | + it "accepts a block" do |
| 22 | + Bugsnag.on_error {|report| report.add_tab(:important, { hello: "world" }) } |
| 23 | + Bugsnag.on_error {|report| report.add_tab(:significant, { hey: "earth" }) } |
| 24 | + |
| 25 | + Bugsnag.notify(RuntimeError.new("Oh no!")) |
| 26 | + |
| 27 | + expect(Bugsnag).to(have_sent_notification do |payload, _headers| |
| 28 | + event = get_event_from_payload(payload) |
| 29 | + |
| 30 | + expect(event["metaData"]["important"]).to eq({ "hello" => "world" }) |
| 31 | + expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" }) |
| 32 | + end) |
| 33 | + end |
| 34 | + |
21 | 35 | it "can add callbacks in a configure block" do
|
22 | 36 | callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
23 | 37 | callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
24 | 38 |
|
25 | 39 | Bugsnag.configure do |config|
|
26 | 40 | config.add_on_error(callback1)
|
27 | 41 | config.add_on_error(callback2)
|
| 42 | + config.on_error do |report| |
| 43 | + report.add_tab(:critical, { hi: "planet" }) |
| 44 | + end |
28 | 45 | end
|
29 | 46 |
|
30 | 47 | Bugsnag.notify(RuntimeError.new("Oh no!"))
|
|
34 | 51 |
|
35 | 52 | expect(event["metaData"]["important"]).to eq({ "hello" => "world" })
|
36 | 53 | expect(event["metaData"]["significant"]).to eq({ "hey" => "earth" })
|
| 54 | + expect(event["metaData"]["critical"]).to eq({ "hi" => "planet" }) |
37 | 55 | end)
|
38 | 56 | end
|
39 | 57 |
|
|
56 | 74 | end)
|
57 | 75 | end
|
58 | 76 |
|
| 77 | + it "can remove an already registered block" do |
| 78 | + callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) } |
| 79 | + callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) } |
| 80 | + |
| 81 | + Bugsnag.add_on_error(callback1) |
| 82 | + |
| 83 | + # pass callback2 as a block so that it can be removed |
| 84 | + Bugsnag.on_error(&callback2) |
| 85 | + |
| 86 | + Bugsnag.remove_on_error(callback2) |
| 87 | + |
| 88 | + Bugsnag.notify(RuntimeError.new("Oh no!")) |
| 89 | + |
| 90 | + expect(Bugsnag).to(have_sent_notification do |payload, _headers| |
| 91 | + event = get_event_from_payload(payload) |
| 92 | + |
| 93 | + expect(event["metaData"]["important"]).to eq({ "hello" => "world" }) |
| 94 | + expect(event["metaData"]["significant"]).to be_nil |
| 95 | + end) |
| 96 | + end |
| 97 | + |
59 | 98 | it "can remove all registered callbacks" do
|
60 | 99 | callback1 = proc {|report| report.add_tab(:important, { hello: "world" }) }
|
61 | 100 | callback2 = proc {|report| report.add_tab(:significant, { hey: "earth" }) }
|
|
0 commit comments