Sha256: 9eefe5021c3cb111c11308abf730c59f9d3a88bb20218dac352db03f9f3847cd

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'bugsnag'

require 'webmock/rspec'
require 'rspec/expectations'

class BugsnagTestException < RuntimeError; end

def get_event_from_payload(payload)
  expect(payload["events"].size).to eq(1)
  payload["events"].first
end

def get_exception_from_payload(payload)
  event = get_event_from_payload(payload)
  expect(event["exceptions"].size).to eq(1)
  event["exceptions"].last
end

def notify_test_exception(*args)
  Bugsnag.notify(RuntimeError.new("test message"), *args)
end

RSpec.configure do |config|
  config.order = "random"

  config.before(:each) do
    WebMock.stub_request(:post, "https://notify.bugsnag.com/")

    Bugsnag.instance_variable_set(:@configuration, Bugsnag::Configuration.new)
    Bugsnag.configure do |config|
      config.api_key = "c9d60ae4c7e70c4b6c4ebd3e8056d2b8"
      config.release_stage = "production"
      config.delivery_method = :synchronous
      # silence logger in tests
      config.logger = Logger.new(StringIO.new)
    end
  end

  config.after(:each) do
    Bugsnag.configuration.clear_request_data
  end
end

def have_sent_notification(&matcher)
  have_requested(:post, "https://notify.bugsnag.com/").with do |request|
    if matcher
      matcher.call JSON.parse(request.body)
    else
      true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bugsnag-2.7.1 spec/spec_helper.rb
bugsnag-2.7.0 spec/spec_helper.rb
bugsnag-2.6.1 spec/spec_helper.rb
bugsnag-2.6.0 spec/spec_helper.rb