Skip to content

Commit

Permalink
Moved test to relevant file, added integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Feb 21, 2018
1 parent a119c30 commit 8da33d5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 26 deletions.
52 changes: 52 additions & 0 deletions spec/bugsnag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,56 @@
expect(Bugsnag.configuration.logger).to have_received(:warn)
end
end

describe "add_exit_handler" do

before do
Bugsnag.reset_exit_handler_added
module Kernel
alias_method :old_at_exit, :at_exit
def at_exit
begin
raise BugsnagTestException.new("Oh no")
rescue
yield
end
end
end
end

it "automatically adds an exit handler" do
expect(Bugsnag).to receive(:register_at_exit)
Bugsnag.configure do |conf|
conf.api_key = "TEST KEY"
end
end

it "calls at_exit when register_at_exit is called" do
expect(Bugsnag).to receive(:at_exit)
Bugsnag.register_at_exit
end

it "doesn't call at_exit on subsequent calls" do
expect(Bugsnag).to receive(:at_exit).once
Bugsnag.register_at_exit
Bugsnag.register_at_exit
end

it "sends an exception when at_exit is called" do
report_mock = double('report')
expect(report_mock).to receive(:severity=).with('error')
expect(report_mock).to receive(:severity_reason=).with({
:type => Bugsnag::Report::UNHANDLED_EXCEPTION
})
expect(Bugsnag).to receive(:notify).with(kind_of(BugsnagTestException), true).and_yield(report_mock)
Bugsnag.register_at_exit
end

after do
module Kernel
alias_method :at_exit, :old_at_exit
end
end

end
end
26 changes: 0 additions & 26 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,4 @@
expect(subject.ignore_classes).to eq(Set.new([SystemExit, Interrupt]))
end

describe "add_exit_handler" do

before do
Bugsnag.reset_exit_handler_added
end

it "automatically adds an exit handler" do
expect(Bugsnag).to receive(:register_at_exit)
Bugsnag.configure do |conf|
conf.api_key = "TEST KEY"
end
end

it "calls at_exit when register_at_exit is called" do
expect(Bugsnag).to receive(:at_exit)
Bugsnag.register_at_exit
end

it "doesn't call at_exit on subsequent calls" do
expect(Bugsnag).to receive(:at_exit).once
Bugsnag.register_at_exit
Bugsnag.register_at_exit
end

end

end

0 comments on commit 8da33d5

Please sign in to comment.