Sha256: aa7f2aace8f0a537a066422611bf4fa3f9a3a56ed9c050b960e6bf170d9e1fa9

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe DispatchRider::Logging::TextFormatter do
  describe "#format" do
    subject(:format_result) { described_class.new.format(data) }

    let(:data) do
      {
        phase: phase,
        guid: '123',
        body: { foo: :bar },
        subject: 'sample_handler',
      }
    end

    context 'when phase is :complete' do
      let(:phase) { :complete }

      before { data[:duration] = 10 }

      example do
        expect(format_result).to eq("Completed execution of: (123): sample_handler : {:foo=>:bar} in 10.00 seconds")
      end
    end

    context 'when phase is :fail' do
      let(:phase) { :fail }

      before { data[:exception] = { class: StandardError, message: 'Foo is not bar' } }

      example do
        expect(format_result).to eq("Failed execution of: (123): sample_handler with StandardError: Foo is not bar")
      end
    end

    context 'when phase is :start' do
      let(:phase) { :start }

      example do
        expect(format_result).to eq("Starting execution of: (123): sample_handler : {:foo=>:bar}")
      end
    end

    context 'when phase is :success' do
      let(:phase) { :success }

      example do
        expect(format_result).to eq("Succeeded execution of: (123): sample_handler : {:foo=>:bar}")
      end
    end

    context 'when phase is :stop' do
      let(:phase) { :stop }

      before { data[:reason] = 'Ninja Attack' }

      example do
        expect(format_result).to eq("Got stop (Ninja Attack) while executing: (123): sample_handler : {:foo=>:bar}")
      end
    end

    context 'when phase is :error_handler_fail' do
      let(:phase) { :error_handler_fail }

      before { data[:exception] = { class: StandardError, message: 'Foo is not bar' } }

      example do
        expect(format_result).to eq(
          "Failed error handling of: (123): sample_handler with StandardError: Foo is not bar"
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-2.2.0 spec/lib/dispatch-rider/logging/text_formatter_spec.rb