Sha256: 55fea95a3e49e47db6a8f4cea37a6a1b7653ae9dbbae8fd8dc2f7865bdb50d0e

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

RSpec.describe BloodContracts::Instrumentation::SessionRecording do
  before do
    BCI.reset_config!
    module Test
      class PhoneType < BC::Refined
        REGEX = /\A(\+7|8)(9|8)\d{9}\z/i
        def match
          context[:phone_input] = value.to_s
          return failure(:invalid_phone) if context[:phone_input] !~ REGEX
          context[:phone] = context[:phone_input]
          self
        end
      end

      class CustomInstrument
        def call(session)
          "[SID:#{session.id}] #{session.result_type_name}"
        end

        def before(session)
          session.extras[:started] = true
        end

        def after(session)
          session.extras[:finished] = true
        end
      end
    end

    BCI.configure { |cfg| cfg.instrument "Phone", custom_instrument }
  end

  let(:custom_instrument) { Test::CustomInstrument.new }

  it do
    expect(Test::PhoneType.instruments).to match_array([custom_instrument])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blood_contracts-instrumentation-0.1.1 spec/blood_contracts/instrumentation/session_recording_spec.rb