Sha256: d3182acf9a68d6fdf99342a9bc67dafd13a44fe6fbdc932b987716b2cced3d35

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

RSpec.describe 'Subscribing to instrumentation events' do
  subject(:notifications) { Dry::Monitor::Notifications.new(:app) }

  before do
    Dry::Monitor::Notifications.register_event(:sql, name: 'rom[sql]')
  end

  describe '#instrument' do
    it 'allows subscribing via block' do
      captured = []
      payload = { query: 'SELECT 1 FROM users' }

      notifications.subscribe(:sql) do |event|
        captured << [event.id, event[:query]]
      end

      notifications.instrument(:sql, payload)

      expect(captured).to eql([[:sql, 'SELECT 1 FROM users']])
    end

    it 'allows instrumenting via block' do
      captured = []
      payload = { query: 'SELECT 1 FROM users' }

      notifications.subscribe(:sql) do |event|
        captured << [event.id, event[:query]]
      end

      notifications.instrument(:sql, payload) do
        payload
      end

      expect(captured).to eql([[:sql, 'SELECT 1 FROM users']])
    end

    it 'allows instrumenting via block when no payload given' do
      captured = []

      notifications.subscribe(:sql) do |event|
        captured << [event.id]
      end

      notifications.instrument(:sql) {}

      expect(captured).to eql([[:sql]])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-monitor-0.3.1 spec/integration/instrumentation_spec.rb