|
| 1 | +require "spec_helper" |
| 2 | +require "sentry/integrable" |
| 3 | + |
| 4 | +RSpec.describe Sentry::Integrable do |
| 5 | + module Sentry |
| 6 | + module FakeIntegration |
| 7 | + extend Sentry::Integrable |
| 8 | + |
| 9 | + register_integration name: "fake_integration", version: "0.1.0" |
| 10 | + end |
| 11 | + end |
| 12 | + |
| 13 | + it "registers correct meta" do |
| 14 | + meta = Sentry.integrations["fake_integration"] |
| 15 | + |
| 16 | + expect(meta).to eq({ name: "sentry.ruby.fake_integration", version: "0.1.0" }) |
| 17 | + end |
| 18 | + |
| 19 | + describe "helpers generation" do |
| 20 | + before do |
| 21 | + perform_basic_setup |
| 22 | + end |
| 23 | + |
| 24 | + let(:exception) { ZeroDivisionError.new("1/0") } |
| 25 | + let(:message) { "test message" } |
| 26 | + |
| 27 | + it "generates Sentry::FakeIntegration.capture_exception" do |
| 28 | + hint = nil |
| 29 | + |
| 30 | + Sentry.configuration.before_send = lambda do |event, h| |
| 31 | + hint = h |
| 32 | + event |
| 33 | + end |
| 34 | + |
| 35 | + Sentry::FakeIntegration.capture_exception(exception, hint: { additional_hint: "foo" }) |
| 36 | + |
| 37 | + expect(hint).to eq({ additional_hint: "foo", integration: "fake_integration", exception: exception }) |
| 38 | + end |
| 39 | + |
| 40 | + it "generates Sentry::FakeIntegration.capture_exception" do |
| 41 | + hint = nil |
| 42 | + |
| 43 | + Sentry.configuration.before_send = lambda do |event, h| |
| 44 | + hint = h |
| 45 | + event |
| 46 | + end |
| 47 | + |
| 48 | + Sentry::FakeIntegration.capture_message(message, hint: { additional_hint: "foo" }) |
| 49 | + |
| 50 | + expect(hint).to eq({ additional_hint: "foo", integration: "fake_integration", message: message }) |
| 51 | + end |
| 52 | + |
| 53 | + it "sets correct meta when the event is captured by integration helpers" do |
| 54 | + event = Sentry::FakeIntegration.capture_message(message) |
| 55 | + expect(event.sdk).to eq({ name: "sentry.ruby.fake_integration", version: "0.1.0" }) |
| 56 | + end |
| 57 | + |
| 58 | + it "doesn't change the events captured by original helpers" do |
| 59 | + event = Sentry.capture_message(message) |
| 60 | + expect(event.sdk).to eq(Sentry.sdk_meta) |
| 61 | + end |
| 62 | + end |
| 63 | +end |
0 commit comments