Sha256: 35d6d3e2dbff73df83816f465556beb0bc8851d4f9d76a3afae04ae08b95c223

Contents?: true

Size: 1.07 KB

Versions: 14

Compression:

Stored size: 1.07 KB

Contents

require 'helper'

RSpec.describe HTTP2::Emitter do
  class Worker
    include Emitter
  end

  before(:each) do
    @w = Worker.new
    @cnt = 0
  end

  it 'should raise error on missing callback' do
    expect { @w.on(:a) {} }.to_not raise_error
    expect { @w.on(:a) }.to raise_error
  end

  it 'should allow multiple callbacks on single event' do
    @w.on(:a) { @cnt += 1 }
    @w.on(:a) { @cnt += 1 }
    @w.emit(:a)

    expect(@cnt).to eq 2
  end

  it 'should execute callback with optional args' do
    args = nil
    @w.on(:a) { |a| args = a }
    @w.emit(:a, 123)

    expect(args).to eq 123
  end

  it 'should pass emitted callbacks to listeners' do
    @w.on(:a)   { |&block| block.call }
    @w.once(:a) { |&block| block.call }
    @w.emit(:a) { @cnt += 1 }

    expect(@cnt).to eq 2
  end

  it 'should allow events with no callbacks' do
    expect { @w.emit(:missing) }.to_not raise_error
  end

  it 'should execute callback exactly once' do
    @w.on(:a)   { @cnt += 1 }
    @w.once(:a) { @cnt += 1 }
    @w.emit(:a)
    @w.emit(:a)

    expect(@cnt).to eq 3
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
http-2-0.11.0 spec/emitter_spec.rb
http-2-0.10.2 spec/emitter_spec.rb
http-2-0.10.1 spec/emitter_spec.rb
http-2-0.10.0 spec/emitter_spec.rb
http-2-0.9.1 spec/emitter_spec.rb
http-2-0.9.0 spec/emitter_spec.rb
http-2-0.8.4 spec/emitter_spec.rb
http-2-0.8.3 spec/emitter_spec.rb
http-2-0.8.2 spec/emitter_spec.rb
http-2-0.8.1 spec/emitter_spec.rb
mieps_http-2-0.8.2 spec/emitter_spec.rb
mieps_http-2-0.8.1 spec/emitter_spec.rb
mieps_http-2-0.8.0 spec/emitter_spec.rb
http-2-0.8.0 spec/emitter_spec.rb