Sha256: 48545c7fa29555ea056eeddb09ddd1a367aa17b088e36b5cda808ba09035a99d

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe DispatchRider::Callbacks::Access do
  describe "#invoke" do
    subject { described_class.new(storage) }

    let(:callback_a1) { proc { |x| x.call } }
    let(:callback_a2) { proc { |x| x.call } }
    let(:callback_a3) { proc { |x| x.call } }
    let(:callbacks_a) { [callback_a1, callback_a2, callback_a3] }

    let(:callback_b1) { proc { |x| x.call } }
    let(:callbacks_b) { [callback_b1] }

    let(:storage) { DispatchRider::Callbacks::Storage.new }
    let(:action) { proc {} }

    before do
      callbacks_a.each do |cb|
        storage.around :event1, cb
      end
      callbacks_b.each do |cb|
        storage.around :event2, cb
      end
    end

    example "a bunch of handlers" do
      expect(callback_a1).to receive(:call).once.and_call_original
      expect(callback_a2).to receive(:call).once.and_call_original
      expect(callback_a3).to receive(:call).once.and_call_original
      expect(callback_b1).not_to receive(:call)

      expect(action).to receive(:call).once.and_call_original

      subject.invoke(:event1, &action)
    end

    example "single handler" do
      expect(callback_a1).not_to receive(:call)
      expect(callback_a2).not_to receive(:call)
      expect(callback_a3).not_to receive(:call)
      expect(callback_b1).to receive(:call).once.and_call_original

      expect(action).to receive(:call).once.and_call_original

      subject.invoke(:event2, &action)
    end

    example "no handlers" do
      expect(callback_a1).not_to receive(:call)
      expect(callback_a2).not_to receive(:call)
      expect(callback_a3).not_to receive(:call)
      expect(callback_b1).not_to receive(:call)

      expect(action).to receive(:call).once.and_call_original

      subject.invoke(:event3, &action)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-2.2.0 spec/lib/dispatch-rider/callbacks/access_spec.rb