Sha256: b1d29e1aa8661fa66e7ea5d9060bac9d9294148d9afb1af89a22bbdc90f0a3da

Contents?: true

Size: 1.21 KB

Versions: 32

Compression:

Stored size: 1.21 KB

Contents

require 'flipper/instrumenters/memory'

RSpec.describe Flipper::Instrumenters::Memory do
  describe '#initialize' do
    it 'sets events to empty array' do
      instrumenter = described_class.new
      expect(instrumenter.events).to eq([])
    end
  end

  describe '#instrument' do
    it 'adds to events' do
      instrumenter = described_class.new
      name         = 'user.signup'
      payload      = { email: 'john@doe.com' }
      block_result = :yielded

      result = instrumenter.instrument(name, payload) { block_result }
      expect(result).to eq(block_result)

      event = described_class::Event.new(name, payload, block_result)
      expect(instrumenter.events).to eq([event])
    end

    context 'when an error is raised' do
      subject do
        instrumenter.instrument(:name) { raise IOError }
      end

      let(:instrumenter) { described_class.new }

      it 'captures and propagates the error' do
        expect { subject }.to raise_error(IOError)

        expect(instrumenter.events.count).to be 1

        payload = instrumenter.events[0].payload
        expect(payload.keys).to include(:exception, :exception_object)
        expect(payload[:exception_object]).to be_a IOError
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
flipper-0.26.0 spec/flipper/instrumenters/memory_spec.rb
flipper-0.26.0.rc2 spec/flipper/instrumenters/memory_spec.rb
flipper-0.26.0.rc1 spec/flipper/instrumenters/memory_spec.rb
flipper-0.25.4 spec/flipper/instrumenters/memory_spec.rb
flipper-0.25.3 spec/flipper/instrumenters/memory_spec.rb
flipper-0.25.2 spec/flipper/instrumenters/memory_spec.rb
flipper-0.25.1 spec/flipper/instrumenters/memory_spec.rb
flipper-0.25.0 spec/flipper/instrumenters/memory_spec.rb
flipper-0.24.1 spec/flipper/instrumenters/memory_spec.rb
flipper-0.24.0 spec/flipper/instrumenters/memory_spec.rb
flipper-0.23.1 spec/flipper/instrumenters/memory_spec.rb
flipper-0.23.0 spec/flipper/instrumenters/memory_spec.rb