Sha256: b751747899456f4bd66dfed54de9267ee738c05f7477bfb85bc3e91792f41dc5

Contents?: true

Size: 827 Bytes

Versions: 10

Compression:

Stored size: 827 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' }

    its(:event) { is_expected.to be_a Reactor::Event }
    its('event.some') { is_expected.to eq('random') }

    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

10 entries across 10 versions & 1 rubygems

Version Path
reactor-0.10.0 spec/models/subscriber_spec.rb
reactor-0.9.9 spec/models/subscriber_spec.rb
reactor-0.9.8 spec/models/subscriber_spec.rb
reactor-0.9.7 spec/models/subscriber_spec.rb
reactor-0.9.6 spec/models/subscriber_spec.rb
reactor-0.9.5 spec/models/subscriber_spec.rb
reactor-0.9.4 spec/models/subscriber_spec.rb
reactor-0.9.2 spec/models/subscriber_spec.rb
reactor-0.9.1 spec/models/subscriber_spec.rb
reactor-0.9.0 spec/models/subscriber_spec.rb