Wednesday, July 15, 2026 2:52:27 AM
> project show esm_bot
A sophisticated Discord bot that bridges Arma 3 Exile servers with Discord communities. Built in Ruby with secure TCP communication, it delivers territory management, real-time notifications, and comprehensive server administration right in your Discord channels.
Details
> timer_task_spec.rb
# frozen_string_literal: true

RSpec.describe ESM::TimerTask do
  describe ".execute" do
    # The work runs on a background timer thread, so reach past Concurrent and capture the block it
    # hands off, then drive it synchronously. The rescue wrapper is the only behavior this class adds.
    subject(:wrapped_task) do
      captured = nil
      allow(Concurrent::TimerTask).to receive(:execute) { |**_options, &block| captured = block }

      described_class.execute(&work)
      captured
    end

    before { allow(ESM.logger).to receive(:error!) }

    context "when the work raises a StandardError" do
      let(:work) { -> { raise ArgumentError, "boom" } }

      it "logs the error and swallows it" do
        expect { wrapped_task.call }.not_to raise_error
        expect(ESM.logger).to have_received(:error!).with(error: an_instance_of(ArgumentError))
      end
    end

    context "when the work raises outside the StandardError hierarchy" do
      let(:work) { -> { raise SystemStackError } }

      it "logs the error and swallows it" do
        expect { wrapped_task.call }.not_to raise_error
        expect(ESM.logger).to have_received(:error!).with(error: an_instance_of(SystemStackError))
      end
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 43aa0d7