Sha256: b6a8f374c7a626f6395e668a3db6660762d340b3c8346018de454694b259b680

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 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 |bugsnag|
      bugsnag.api_key = "c9d60ae4c7e70c4b6c4ebd3e8056d2b8"
      bugsnag.release_stage = "production"
      bugsnag.delivery_method = :synchronous
      # silence logger in tests
      bugsnag.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)
      true
    else
      raise "no matcher provided to have_sent_notification (did you use { })"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bugsnag-5.5.0 spec/spec_helper.rb
bugsnag-5.4.1 spec/spec_helper.rb
bugsnag-5.4.0 spec/spec_helper.rb
bugsnag-5.3.3 spec/spec_helper.rb
bugsnag-5.3.2 spec/spec_helper.rb
bugsnag-5.3.1 spec/spec_helper.rb
bugsnag-5.3.0 spec/spec_helper.rb
bugsnag-5.2.0 spec/spec_helper.rb
bugsnag-5.1.0 spec/spec_helper.rb
bugsnag-5.0.1 spec/spec_helper.rb
bugsnag-5.0.0 spec/spec_helper.rb
bugsnag-4.2.1 spec/spec_helper.rb
bugsnag-4.2.0 spec/spec_helper.rb
bugsnag-4.1.0 spec/spec_helper.rb
bugsnag-4.0.2 spec/spec_helper.rb
bugsnag-4.0.1 spec/spec_helper.rb
bugsnag-4.0.0 spec/spec_helper.rb
bugsnag-3.0.0 spec/spec_helper.rb
bugsnag-2.8.13 spec/spec_helper.rb