Sha256: 7c4160e2a00e5792808f07cafaa904872364b29ac4ece62b6b81889879ddf147
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
require 'spec_helper' Reactor.in_test_mode do class SomeClass include Reactor::Subscribable on_event :test_event, -> (event) { self.spy_on_me } end end describe Reactor do let(:subscriber) { SomeClass } describe '.test_mode!' do it 'sets Reactor into test mode' do expect(Reactor.test_mode?).to be_falsey Reactor.test_mode! expect(Reactor.test_mode?).to be_truthy end end context 'in test mode' do before { Reactor.test_mode! } after { Reactor.disable_test_mode! } it 'subscribers created in test mode are disabled' do expect(subscriber).not_to receive :spy_on_me Reactor::Event.publish :test_event end describe '.with_subscriber_enabled' do it 'enables a subscriber during test mode' do expect(subscriber).to receive :spy_on_me Reactor.with_subscriber_enabled(subscriber) do Reactor::Event.publish :test_event end end it 'disables the subscriber outside the block' do expect(Reactor::TEST_MODE_SUBSCRIBERS).to be_empty Reactor.with_subscriber_enabled(subscriber) do expect(Reactor::TEST_MODE_SUBSCRIBERS).to contain_exactly(subscriber) end expect(Reactor::TEST_MODE_SUBSCRIBERS).to be_empty end it 'correctly handles exceptions inside the block' do expect(Reactor::TEST_MODE_SUBSCRIBERS).to be_empty expect { Reactor.with_subscriber_enabled(subscriber) do raise RuntimeError end }.to raise_error(RuntimeError) expect(Reactor::TEST_MODE_SUBSCRIBERS).to be_empty end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
reactor-0.13.0 | spec/reactor_spec.rb |
reactor-0.12.2 | spec/reactor_spec.rb |