spec/notification_spec.rb in bugsnag-2.1.0 vs spec/notification_spec.rb in bugsnag-2.2.0

- old
+ new

@@ -4,10 +4,11 @@ require 'ostruct' module ActiveRecord; class RecordNotFound < RuntimeError; end; end class NestedException < StandardError; attr_accessor :original_exception; end class BugsnagTestExceptionWithMetaData < Exception; include Bugsnag::MetaData; end +class BugsnagSubclassTestException < BugsnagTestException; end class Ruby21Exception < RuntimeError attr_accessor :cause def self.raise!(msg) e = new(msg) @@ -249,14 +250,14 @@ } }) end it "truncates large meta_data before sending" do - expect(Bugsnag::Notification).to receive(:post) do |endpoint, opts| + expect(Bugsnag::Notification).to receive(:do_post) do |endpoint, payload_string| # Truncated body should be no bigger than # 2 truncated hashes (4096*2) + rest of payload (5000) - expect(opts[:body].length).to be < 4096*2 + 5000 + expect(payload_string.length).to be < 4096*2 + 5000 end Bugsnag.notify(BugsnagTestException.new("It crashed"), { :meta_data => { :some_tab => { @@ -491,15 +492,23 @@ expect(Bugsnag::Notification).not_to receive(:deliver_exception_payload) Bugsnag.notify_or_ignore(BugsnagTestException.new("It crashed")) end - it "does not notify if the exception is matched by an ignore_classes lambda function" do - Bugsnag.configuration.ignore_classes << lambda {|e| e.message =~ /crashed/} + it "does not notify if exception's ancestor is an ignored class" do + Bugsnag.configuration.ignore_classes << "BugsnagTestException" expect(Bugsnag::Notification).not_to receive(:deliver_exception_payload) + Bugsnag.notify_or_ignore(BugsnagSubclassTestException.new("It crashed")) + end + + it "accepts both String and Class instances as an ignored class" do + Bugsnag.configuration.ignore_classes << BugsnagTestException + + expect(Bugsnag::Notification).not_to receive(:deliver_exception_payload) + Bugsnag.notify_or_ignore(BugsnagTestException.new("It crashed")) end it "does not notify if the user agent is present and matches a regex in ignore_user_agents" do Bugsnag.configuration.ignore_user_agents << %r{BugsnagUserAgent} @@ -691,11 +700,11 @@ it "should fix invalid utf8" do invalid_data = "fl\xc3ff" invalid_data.force_encoding('BINARY') if invalid_data.respond_to?(:force_encoding) - expect(Bugsnag::Notification).to receive(:post) do |endpoint, opts| - expect(opts[:body]).to match(/fl�ff/) if defined?(Encoding::UTF_8) + expect(Bugsnag::Notification).to receive(:do_post) do |endpoint, payload_string| + expect(payload_string).to match(/fl�ff/) if defined?(Encoding::UTF_8) end notify_test_exception(:fluff => {:fluff => invalid_data}) end