Sha256: 33ba0f9a7aa33f33ff29bb255d8a742a41b299eb7a395ac8e2b6c4e46c432cbd

Contents?: true

Size: 1009 Bytes

Versions: 3

Compression:

Stored size: 1009 Bytes

Contents

require 'spec_helper'

class MySubscriber < Reactor::Subscriber
  attr_accessor :was_called

  on_fire do
    self.was_called = true
  end
end

describe Reactor::Subscriber do

  describe 'fire' do
    subject { MySubscriber.create(event_name: :you_name_it).fire some: 'random', event: 'data' }

    describe '#event' do
      subject { super().event }
      it { is_expected.to be_a Reactor::Event }
    end

    describe '#event' do
      subject { super().event }
      describe '#some' do
        subject { super().some }
        it { is_expected.to eq('random') }
      end
    end

    it 'executes block given' do
      expect(subject.was_called).to be_truthy
    end
  end


  describe 'matcher' do
    it 'can be set to star to bind to all events' do
      MySubscriber.create!(event_name: '*')
      expect_any_instance_of(MySubscriber).to receive(:fire).with(hash_including('random' => 'data', 'event' => 'this_event'))
      Reactor::Event.publish(:this_event, {random: 'data'})
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reactor-0.8.3 spec/models/subscriber_spec.rb
reactor-0.8.2 spec/models/subscriber_spec.rb
reactor-0.8.1 spec/models/subscriber_spec.rb