Sha256: 95e7f91bcaf2c8fe2a7546663a182575b2c515f604914f569b853fa2c232c058

Contents?: true

Size: 845 Bytes

Versions: 26

Compression:

Stored size: 845 Bytes

Contents

class TestInstrumenter

  class << self

    def subscribe(callback, filter=nil, &block)

      # create test instrumenter instance
      instrumenter = TestInstrumenter.new do |name, payload|
        if filter
          callback.call(name, payload) if name =~ filter
        else
          callback.call(name, payload)
        end
      end

      # hook up this instrumenter in the context of the spec
      # (assuming called from RSpec binding)
      spec_binding = block.binding.eval('self')
      spec_binding.instance_exec do
        allow(Taskinator).to receive(:instrumenter).and_return(instrumenter)
      end

      yield
    end

  end

  attr_reader :callback

  def initialize(&block)
    @callback = block
  end

  def instrument(event, payload={})
    @callback.call(event, payload)
    yield(payload) if block_given?
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
taskinator-0.5.2 spec/support/test_instrumenter.rb
taskinator-0.5.1 spec/support/test_instrumenter.rb
taskinator-0.5.0 spec/support/test_instrumenter.rb
taskinator-0.4.7 spec/support/test_instrumenter.rb
taskinator-0.4.6 spec/support/test_instrumenter.rb
taskinator-0.4.5 spec/support/test_instrumenter.rb
taskinator-0.4.4 spec/support/test_instrumenter.rb
taskinator-0.4.3 spec/support/test_instrumenter.rb
taskinator-0.4.2 spec/support/test_instrumenter.rb
taskinator-0.4.1 spec/support/test_instrumenter.rb
taskinator-0.4.0 spec/support/test_instrumenter.rb
taskinator-0.3.16 spec/support/test_instrumenter.rb
taskinator-0.3.15 spec/support/test_instrumenter.rb
taskinator-0.3.14 spec/support/test_instrumenter.rb
taskinator-0.3.13 spec/support/test_instrumenter.rb
taskinator-0.3.12 spec/support/test_instrumenter.rb
taskinator-0.3.11 spec/support/test_instrumenter.rb
taskinator-0.3.10 spec/support/test_instrumenter.rb
taskinator-0.3.9 spec/support/test_instrumenter.rb
taskinator-0.3.7 spec/support/test_instrumenter.rb