require 'rails_helper' RSpec.describe Whoopsie, type: :module do context '#report_and_swallow' do it "calls 'handle_exception' for raised exceptions" do expect(Whoopsie).to receive(:handle_exception) Whoopsie.report_and_swallow do X = 10 / 0 end end context 'when Whoopsie is enabled' do before do Rails.application.config.whoopsie.enable = true end it 'swallows the exception' do expect do Whoopsie.report_and_swallow do X = 10 / 0 end end.to_not raise_error end end context 'when Whoopsie is disabled' do before do Rails.application.config.whoopsie.enable = false end it 'raises the exception' do expect do Whoopsie.report_and_swallow do X = 10 / 0 end end.to raise_error(ZeroDivisionError) end end end end