spec/unit/dry/events/publisher_spec.rb in dry-events-0.1.1 vs spec/unit/dry/events/publisher_spec.rb in dry-events-0.2.0
- old
+ new
@@ -37,10 +37,18 @@
publisher.class.subscribe(:test_event, &listener)
expect(publisher.subscribed?(listener)).to be(true)
end
+
+ it 'raises an exception when subscribing to an unregister event' do
+ listener = -> * { }
+
+ expect {
+ publisher.subscribe(:not_register, &listener)
+ }.to raise_error(Dry::Events::InvalidSubscriberError, /not_register/)
+ end
end
describe '#register_event' do
it 'registers a new event at instance level' do
listener = -> * { }
@@ -80,9 +88,23 @@
publisher.unsubscribe(listener)
publisher.publish(:test_event, message: 'it works')
expect(listener.captured).to eql(['it works'])
+ end
+
+ it 'raises an exception when subscribing with no methods to execute' do
+ listener = Object.new
+
+ expect {
+ publisher.subscribe(listener)
+ }.to raise_error(Dry::Events::InvalidSubscriberError, /never be executed/)
+ end
+
+ it 'does not raise an exception when subscriber has methods for notification' do
+ listener = Object.new
+ def listener.on_test_event; nil; end
+ expect { publisher.subscribe(listener) }.not_to raise_error
end
end
describe '#publish' do
it 'publishes an event' do