From 4564f1dc57aeaaeeffa1093ff0cfd86a7b28e897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20=C5=81asocha?= Date: Tue, 25 Jun 2019 15:30:17 +0200 Subject: [PATCH] Rename RubyEventStore::PubSub::* -> RubyEventStore::* --- contrib/measure/examples/demo | 2 +- .../lib/rails_event_store/all.rb | 2 +- .../lib/rails_event_store/client.rb | 4 +- .../source/docs/instrumentation.html.md | 2 +- .../source/docs/subscribe.html.md | 4 +- ruby_event_store/lib/ruby_event_store.rb | 7 +- .../lib/ruby_event_store/broker.rb | 43 +++++++ .../lib/ruby_event_store/client.rb | 6 +- .../lib/ruby_event_store/dispatcher.rb | 18 +++ .../lib/ruby_event_store/pub_sub.rb | 21 ++++ .../lib/ruby_event_store/pub_sub/broker.rb | 45 ------- .../ruby_event_store/pub_sub/dispatcher.rb | 20 ---- .../ruby_event_store/pub_sub/subscriptions.rb | 110 ------------------ .../lib/ruby_event_store/spec/broker_lint.rb | 6 +- .../lib/ruby_event_store/subscriptions.rb | 108 +++++++++++++++++ ruby_event_store/spec/broker_spec.rb | 8 +- ruby_event_store/spec/dispatcher_spec.rb | 90 +++++++------- .../spec/instrumented_dispatcher_spec.rb | 2 +- ruby_event_store/spec/pub_sub_spec.rb | 45 +++++++ ruby_event_store/spec/subscriptions_spec.rb | 6 +- 20 files changed, 301 insertions(+), 248 deletions(-) create mode 100644 ruby_event_store/lib/ruby_event_store/broker.rb create mode 100644 ruby_event_store/lib/ruby_event_store/dispatcher.rb create mode 100644 ruby_event_store/lib/ruby_event_store/pub_sub.rb delete mode 100644 ruby_event_store/lib/ruby_event_store/pub_sub/broker.rb delete mode 100644 ruby_event_store/lib/ruby_event_store/pub_sub/dispatcher.rb delete mode 100644 ruby_event_store/lib/ruby_event_store/pub_sub/subscriptions.rb create mode 100644 ruby_event_store/lib/ruby_event_store/subscriptions.rb create mode 100644 ruby_event_store/spec/pub_sub_spec.rb diff --git a/contrib/measure/examples/demo b/contrib/measure/examples/demo index 4bb187e6ea..5475ba8ebd 100755 --- a/contrib/measure/examples/demo +++ b/contrib/measure/examples/demo @@ -10,7 +10,7 @@ asn = ActiveSupport::Notifications event_store = RubyEventStore::Client.new( repository: RubyEventStore::InstrumentedRepository.new(RubyEventStore::InMemoryRepository.new, asn), mapper: RubyEventStore::Mappers::InstrumentedMapper.new(RubyEventStore::Mappers::Default.new, asn), - dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::PubSub::Dispatcher.new, asn) + dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::Dispatcher.new, asn) ) DummyEvent = Class.new(RubyEventStore::Event) dummy = DummyEvent.new diff --git a/rails_event_store/lib/rails_event_store/all.rb b/rails_event_store/lib/rails_event_store/all.rb index 1a2fd4b529..655b48259a 100644 --- a/rails_event_store/lib/rails_event_store/all.rb +++ b/rails_event_store/lib/rails_event_store/all.rb @@ -11,7 +11,7 @@ module RailsEventStore Event = RubyEventStore::Event InMemoryRepository = RubyEventStore::InMemoryRepository - Subscriptions = RubyEventStore::PubSub::Subscriptions + Subscriptions = RubyEventStore::Subscriptions Projection = RubyEventStore::Projection WrongExpectedEventVersion = RubyEventStore::WrongExpectedEventVersion InvalidExpectedVersion = RubyEventStore::InvalidExpectedVersion diff --git a/rails_event_store/lib/rails_event_store/client.rb b/rails_event_store/lib/rails_event_store/client.rb index 9fe96c1729..0d01d5acc6 100644 --- a/rails_event_store/lib/rails_event_store/client.rb +++ b/rails_event_store/lib/rails_event_store/client.rb @@ -4,10 +4,10 @@ class Client < RubyEventStore::Client def initialize(repository: RailsEventStoreActiveRecord::EventRepository.new, mapper: RubyEventStore::Mappers::Default.new, - subscriptions: RubyEventStore::PubSub::Subscriptions.new, + subscriptions: RubyEventStore::Subscriptions.new, dispatcher: RubyEventStore::ComposedDispatcher.new( RubyEventStore::ImmediateAsyncDispatcher.new(scheduler: ActiveJobScheduler.new), - RubyEventStore::PubSub::Dispatcher.new), + RubyEventStore::Dispatcher.new), request_metadata: default_request_metadata) super(repository: RubyEventStore::InstrumentedRepository.new(repository, ActiveSupport::Notifications), mapper: RubyEventStore::Mappers::InstrumentedMapper.new(mapper, ActiveSupport::Notifications), diff --git a/railseventstore.org/source/docs/instrumentation.html.md b/railseventstore.org/source/docs/instrumentation.html.md index dd67c15f44..e85e00e387 100644 --- a/railseventstore.org/source/docs/instrumentation.html.md +++ b/railseventstore.org/source/docs/instrumentation.html.md @@ -18,7 +18,7 @@ That having said, if you want to instrument your event store with `ActiveSupport ```ruby repository = RailsEventStoreActiveRecord::EventRepository.new # or other repo you use -dispatcher = RubyEventStore::PubSub::Dispatcher.new # or other dispatcher you use +dispatcher = RubyEventStore::Dispatcher.new # or other dispatcher you use RubyEventStore::Client.new( repository: InstrumentedRepository.new(repository, ActiveSupport::Notifications), dispatcher: InstrumentedDispatcher.new(dispatcher, ActiveSupport::Notifications) diff --git a/railseventstore.org/source/docs/subscribe.html.md b/railseventstore.org/source/docs/subscribe.html.md index 4dbcae0a25..760ed78542 100644 --- a/railseventstore.org/source/docs/subscribe.html.md +++ b/railseventstore.org/source/docs/subscribe.html.md @@ -300,7 +300,7 @@ Often you will want to be able to specify both asynchronous and synchronous disp event_store = RailsEventStore::Client.new( dispatcher: RubyEventStore::ComposedDispatcher.new( RubyEventStore::ImmediateAsyncDispatcher.new(scheduler: CustomScheduler.new), # our asynchronous dispatcher, which expects that subscriber respond to `perform_async` method - RubyEventStore::PubSub::Dispatcher.new # regular synchronous dispatcher + RubyEventStore::Dispatcher.new # regular synchronous dispatcher ) ) ``` @@ -377,7 +377,7 @@ end event_store = RailsEventStore::Client.new( dispatcher: RubyEventStore::ComposedDispatcher.new( RailsEventStore::AfterCommitAsyncDispatcher.new(scheduler: RailsEventStore::ActiveJobScheduler.new), - RubyEventStore::PubSub::Dispatcher.new + RubyEventStore::Dispatcher.new ) ) diff --git a/ruby_event_store/lib/ruby_event_store.rb b/ruby_event_store/lib/ruby_event_store.rb index 7424a8d156..eecbcfd4fb 100644 --- a/ruby_event_store/lib/ruby_event_store.rb +++ b/ruby_event_store/lib/ruby_event_store.rb @@ -1,6 +1,7 @@ -require 'ruby_event_store/pub_sub/dispatcher' -require 'ruby_event_store/pub_sub/subscriptions' -require 'ruby_event_store/pub_sub/broker' +require 'ruby_event_store/dispatcher' +require 'ruby_event_store/subscriptions' +require 'ruby_event_store/broker' +require 'ruby_event_store/pub_sub' require 'ruby_event_store/in_memory_repository' require 'ruby_event_store/projection' require 'ruby_event_store/errors' diff --git a/ruby_event_store/lib/ruby_event_store/broker.rb b/ruby_event_store/lib/ruby_event_store/broker.rb new file mode 100644 index 0000000000..f8d6ee0feb --- /dev/null +++ b/ruby_event_store/lib/ruby_event_store/broker.rb @@ -0,0 +1,43 @@ +module RubyEventStore + class Broker + def initialize(subscriptions:, dispatcher:) + @subscriptions = subscriptions + @dispatcher = dispatcher + end + + def call(event, serialized_event) + subscribers = subscriptions.all_for(event.type) + subscribers.each do |subscriber| + dispatcher.call(subscriber, event, serialized_event) + end + end + + def add_subscription(subscriber, event_types) + verify_subscription(subscriber) + subscriptions.add_subscription(subscriber, event_types) + end + + def add_global_subscription(subscriber) + verify_subscription(subscriber) + subscriptions.add_global_subscription(subscriber) + end + + def add_thread_subscription(subscriber, event_types) + verify_subscription(subscriber) + subscriptions.add_thread_subscription(subscriber, event_types) + end + + def add_thread_global_subscription(subscriber) + verify_subscription(subscriber) + subscriptions.add_thread_global_subscription(subscriber) + end + + private + attr_reader :subscriptions, :dispatcher + + def verify_subscription(subscriber) + raise SubscriberNotExist, "subscriber must be first argument or block" unless subscriber + raise InvalidHandler.new("Handler #{subscriber} is invalid for dispatcher #{dispatcher}") unless dispatcher.verify(subscriber) + end + end +end diff --git a/ruby_event_store/lib/ruby_event_store/client.rb b/ruby_event_store/lib/ruby_event_store/client.rb index 9ab386622b..11d994429f 100644 --- a/ruby_event_store/lib/ruby_event_store/client.rb +++ b/ruby_event_store/lib/ruby_event_store/client.rb @@ -5,12 +5,12 @@ class Client def initialize(repository:, mapper: Mappers::Default.new, - subscriptions: PubSub::Subscriptions.new, - dispatcher: PubSub::Dispatcher.new, + subscriptions: Subscriptions.new, + dispatcher: Dispatcher.new, clock: ->{ Time.now.utc }) @repository = repository @mapper = mapper - @broker = PubSub::Broker.new(subscriptions: subscriptions, dispatcher: dispatcher) + @broker = Broker.new(subscriptions: subscriptions, dispatcher: dispatcher) @clock = clock @metadata = Concurrent::ThreadLocalVar.new end diff --git a/ruby_event_store/lib/ruby_event_store/dispatcher.rb b/ruby_event_store/lib/ruby_event_store/dispatcher.rb new file mode 100644 index 0000000000..dc185bf133 --- /dev/null +++ b/ruby_event_store/lib/ruby_event_store/dispatcher.rb @@ -0,0 +1,18 @@ +module RubyEventStore + class Dispatcher + def call(subscriber, event, _) + subscriber = subscriber.new if Class === subscriber + subscriber.call(event) + end + + def verify(subscriber) + begin + subscriber_instance = Class === subscriber ? subscriber.new : subscriber + rescue ArgumentError + false + else + subscriber_instance.respond_to?(:call) + end + end + end +end diff --git a/ruby_event_store/lib/ruby_event_store/pub_sub.rb b/ruby_event_store/lib/ruby_event_store/pub_sub.rb new file mode 100644 index 0000000000..86fae0342d --- /dev/null +++ b/ruby_event_store/lib/ruby_event_store/pub_sub.rb @@ -0,0 +1,21 @@ +module RubyEventStore + module PubSub + def self.const_missing(const_name) + if const_name.equal?(:Subscriptions) + warn "`RubyEventStore::PubSub::Subscriptions` has been deprecated. Use `RubyEventStore::Subscriptions` instead." + + Subscriptions + elsif const_name.equal?(:Broker) + warn "`RubyEventStore::PubSub::Broker` has been deprecated. Use `RubyEventStore::Broker` instead." + + Broker + elsif const_name.equal?(:Dispatcher) + warn "`RubyEventStore::PubSub::Dispatcher` has been deprecated. Use `RubyEventStore::Dispatcher` instead." + + Dispatcher + else + super + end + end + end +end diff --git a/ruby_event_store/lib/ruby_event_store/pub_sub/broker.rb b/ruby_event_store/lib/ruby_event_store/pub_sub/broker.rb deleted file mode 100644 index dd90adf6eb..0000000000 --- a/ruby_event_store/lib/ruby_event_store/pub_sub/broker.rb +++ /dev/null @@ -1,45 +0,0 @@ -module RubyEventStore - module PubSub - class Broker - def initialize(subscriptions:, dispatcher:) - @subscriptions = subscriptions - @dispatcher = dispatcher - end - - def call(event, serialized_event) - subscribers = subscriptions.all_for(event.type) - subscribers.each do |subscriber| - dispatcher.call(subscriber, event, serialized_event) - end - end - - def add_subscription(subscriber, event_types) - verify_subscription(subscriber) - subscriptions.add_subscription(subscriber, event_types) - end - - def add_global_subscription(subscriber) - verify_subscription(subscriber) - subscriptions.add_global_subscription(subscriber) - end - - def add_thread_subscription(subscriber, event_types) - verify_subscription(subscriber) - subscriptions.add_thread_subscription(subscriber, event_types) - end - - def add_thread_global_subscription(subscriber) - verify_subscription(subscriber) - subscriptions.add_thread_global_subscription(subscriber) - end - - private - attr_reader :subscriptions, :dispatcher - - def verify_subscription(subscriber) - raise SubscriberNotExist, "subscriber must be first argument or block" unless subscriber - raise InvalidHandler.new("Handler #{subscriber} is invalid for dispatcher #{dispatcher}") unless dispatcher.verify(subscriber) - end - end - end -end diff --git a/ruby_event_store/lib/ruby_event_store/pub_sub/dispatcher.rb b/ruby_event_store/lib/ruby_event_store/pub_sub/dispatcher.rb deleted file mode 100644 index 98ce5d2d56..0000000000 --- a/ruby_event_store/lib/ruby_event_store/pub_sub/dispatcher.rb +++ /dev/null @@ -1,20 +0,0 @@ -module RubyEventStore - module PubSub - class Dispatcher - def call(subscriber, event, _) - subscriber = subscriber.new if Class === subscriber - subscriber.call(event) - end - - def verify(subscriber) - begin - subscriber_instance = Class === subscriber ? subscriber.new : subscriber - rescue ArgumentError - false - else - subscriber_instance.respond_to?(:call) - end - end - end - end -end diff --git a/ruby_event_store/lib/ruby_event_store/pub_sub/subscriptions.rb b/ruby_event_store/lib/ruby_event_store/pub_sub/subscriptions.rb deleted file mode 100644 index daa08f493a..0000000000 --- a/ruby_event_store/lib/ruby_event_store/pub_sub/subscriptions.rb +++ /dev/null @@ -1,110 +0,0 @@ -require 'concurrent' - -module RubyEventStore - module PubSub - class Subscriptions - def initialize - @local = LocalSubscriptions.new - @global = GlobalSubscriptions.new - @thread = ThreadSubscriptions.new - end - - def add_subscription(subscriber, event_types) - local.add(subscriber, event_types) - end - - def add_global_subscription(subscriber) - global.add(subscriber) - end - - def add_thread_subscription(subscriber, event_types) - thread.local.add(subscriber, event_types) - end - - def add_thread_global_subscription(subscriber) - thread.global.add(subscriber) - end - - def all_for(event_type) - [local, global, thread].map{|r| r.all_for(event_type)}.reduce(&:+) - end - - private - attr_reader :local, :global, :thread - - class ThreadSubscriptions - def initialize - @local = ThreadLocalSubscriptions.new - @global = ThreadGlobalSubscriptions.new - end - attr_reader :local, :global - - def all_for(event_type) - [global, local].map{|r| r.all_for(event_type)}.reduce(&:+) - end - end - - class LocalSubscriptions - def initialize - @subscriptions = Hash.new {|hsh, key| hsh[key] = [] } - end - - def add(subscription, event_types) - event_types.each{ |type| @subscriptions[type.to_s] << subscription } - ->() {event_types.each{ |type| @subscriptions.fetch(type.to_s).delete(subscription) } } - end - - def all_for(event_type) - @subscriptions[event_type] - end - end - - class GlobalSubscriptions - def initialize - @subscriptions = [] - end - - def add(subscription) - @subscriptions << subscription - ->() { @subscriptions.delete(subscription) } - end - - def all_for(_event_type) - @subscriptions - end - end - - class ThreadLocalSubscriptions - def initialize - @subscriptions = Concurrent::ThreadLocalVar.new do - Hash.new {|hsh, key| hsh[key] = [] } - end - end - - def add(subscription, event_types) - event_types.each{ |type| @subscriptions.value[type.to_s] << subscription } - ->() {event_types.each{ |type| @subscriptions.value.fetch(type.to_s).delete(subscription) } } - end - - def all_for(event_type) - @subscriptions.value[event_type] - end - end - - class ThreadGlobalSubscriptions - def initialize - @subscriptions = Concurrent::ThreadLocalVar.new([]) - end - - def add(subscription) - @subscriptions.value += [subscription] - ->() { @subscriptions.value -= [subscription] } - end - - def all_for(_event_type) - @subscriptions.value - end - end - end - end -end diff --git a/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb b/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb index 08728a8ac7..8e5d1be5c8 100644 --- a/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb +++ b/ruby_event_store/lib/ruby_event_store/spec/broker_lint.rb @@ -2,8 +2,8 @@ let(:event) { instance_double(::RubyEventStore::Event, type: 'EventType') } let(:serialized_event) { instance_double(::RubyEventStore::SerializedRecord) } let(:handler) { HandlerClass.new } - let(:subscriptions) { ::RubyEventStore::PubSub::Subscriptions.new } - let(:dispatcher) { ::RubyEventStore::PubSub::Dispatcher.new } + let(:subscriptions) { ::RubyEventStore::Subscriptions.new } + let(:dispatcher) { ::RubyEventStore::Dispatcher.new } let(:broker) { broker_klass.new(subscriptions: subscriptions, dispatcher: dispatcher) } specify "no dispatch when no subscriptions" do @@ -42,7 +42,7 @@ allow(dispatcher).to receive(:verify).and_return(false) expect do broker.add_subscription(HandlerClass, []) - end.to raise_error(RubyEventStore::InvalidHandler, /Handler HandlerClass is invalid for dispatcher .*PubSub::Dispatcher/) + end.to raise_error(RubyEventStore::InvalidHandler, /Handler HandlerClass is invalid for dispatcher .*Dispatcher/) expect do broker.add_global_subscription(HandlerClass) end.to raise_error(RubyEventStore::InvalidHandler, /is invalid for dispatcher/) diff --git a/ruby_event_store/lib/ruby_event_store/subscriptions.rb b/ruby_event_store/lib/ruby_event_store/subscriptions.rb new file mode 100644 index 0000000000..478a14cedd --- /dev/null +++ b/ruby_event_store/lib/ruby_event_store/subscriptions.rb @@ -0,0 +1,108 @@ +require 'concurrent' + +module RubyEventStore + class Subscriptions + def initialize + @local = LocalSubscriptions.new + @global = GlobalSubscriptions.new + @thread = ThreadSubscriptions.new + end + + def add_subscription(subscriber, event_types) + local.add(subscriber, event_types) + end + + def add_global_subscription(subscriber) + global.add(subscriber) + end + + def add_thread_subscription(subscriber, event_types) + thread.local.add(subscriber, event_types) + end + + def add_thread_global_subscription(subscriber) + thread.global.add(subscriber) + end + + def all_for(event_type) + [local, global, thread].map{|r| r.all_for(event_type)}.reduce(&:+) + end + + private + attr_reader :local, :global, :thread + + class ThreadSubscriptions + def initialize + @local = ThreadLocalSubscriptions.new + @global = ThreadGlobalSubscriptions.new + end + attr_reader :local, :global + + def all_for(event_type) + [global, local].map{|r| r.all_for(event_type)}.reduce(&:+) + end + end + + class LocalSubscriptions + def initialize + @subscriptions = Hash.new {|hsh, key| hsh[key] = [] } + end + + def add(subscription, event_types) + event_types.each{ |type| @subscriptions[type.to_s] << subscription } + ->() {event_types.each{ |type| @subscriptions.fetch(type.to_s).delete(subscription) } } + end + + def all_for(event_type) + @subscriptions[event_type] + end + end + + class GlobalSubscriptions + def initialize + @subscriptions = [] + end + + def add(subscription) + @subscriptions << subscription + ->() { @subscriptions.delete(subscription) } + end + + def all_for(_event_type) + @subscriptions + end + end + + class ThreadLocalSubscriptions + def initialize + @subscriptions = Concurrent::ThreadLocalVar.new do + Hash.new {|hsh, key| hsh[key] = [] } + end + end + + def add(subscription, event_types) + event_types.each{ |type| @subscriptions.value[type.to_s] << subscription } + ->() {event_types.each{ |type| @subscriptions.value.fetch(type.to_s).delete(subscription) } } + end + + def all_for(event_type) + @subscriptions.value[event_type] + end + end + + class ThreadGlobalSubscriptions + def initialize + @subscriptions = Concurrent::ThreadLocalVar.new([]) + end + + def add(subscription) + @subscriptions.value += [subscription] + ->() { @subscriptions.value -= [subscription] } + end + + def all_for(_event_type) + @subscriptions.value + end + end + end +end diff --git a/ruby_event_store/spec/broker_spec.rb b/ruby_event_store/spec/broker_spec.rb index 7b6e85c768..a15c223ea8 100644 --- a/ruby_event_store/spec/broker_spec.rb +++ b/ruby_event_store/spec/broker_spec.rb @@ -2,11 +2,7 @@ require 'ruby_event_store/spec/broker_lint' module RubyEventStore - module PubSub - - RSpec.describe Broker do - it_behaves_like :broker, Broker - end - + RSpec.describe Broker do + it_behaves_like :broker, Broker end end diff --git a/ruby_event_store/spec/dispatcher_spec.rb b/ruby_event_store/spec/dispatcher_spec.rb index 9d50b76c2a..9f834d8dc8 100644 --- a/ruby_event_store/spec/dispatcher_spec.rb +++ b/ruby_event_store/spec/dispatcher_spec.rb @@ -2,62 +2,60 @@ require 'ruby_event_store/spec/dispatcher_lint' module RubyEventStore - module PubSub - RSpec.describe Dispatcher do - it_behaves_like :dispatcher, Dispatcher.new - let(:event) { instance_double(::RubyEventStore::Event) } - let(:serialized_event) { instance_double(::RubyEventStore::SerializedRecord) } - let(:handler) { HandlerClass.new } - - specify "does not allow silly subscribers" do - expect(Dispatcher.new.verify(:symbol)).to eq(false) - expect(Dispatcher.new.verify(Object.new)).to eq(false) - end + RSpec.describe Dispatcher do + it_behaves_like :dispatcher, Dispatcher.new + let(:event) { instance_double(::RubyEventStore::Event) } + let(:serialized_event) { instance_double(::RubyEventStore::SerializedRecord) } + let(:handler) { HandlerClass.new } + + specify "does not allow silly subscribers" do + expect(Dispatcher.new.verify(:symbol)).to eq(false) + expect(Dispatcher.new.verify(Object.new)).to eq(false) + end - specify "does not allow class without instance method #call" do - klass = Class.new - expect(Dispatcher.new.verify(klass)).to eq(false) - end + specify "does not allow class without instance method #call" do + klass = Class.new + expect(Dispatcher.new.verify(klass)).to eq(false) + end - specify "does not allow class without constructor requiring arguments" do - klass = Class.new do - def initialize(something) - @something = something - end + specify "does not allow class without constructor requiring arguments" do + klass = Class.new do + def initialize(something) + @something = something + end - def call - end + def call end - expect(Dispatcher.new.verify(klass)).to eq(false) end + expect(Dispatcher.new.verify(klass)).to eq(false) + end - specify "calls subscribed instance" do - expect(handler).to receive(:call).with(event) - Dispatcher.new.call(handler, event, serialized_event) - end + specify "calls subscribed instance" do + expect(handler).to receive(:call).with(event) + Dispatcher.new.call(handler, event, serialized_event) + end - specify "calls subscribed class" do - expect(HandlerClass).to receive(:new).and_return(handler) - expect(handler).to receive(:call).with(event) - Dispatcher.new.call(HandlerClass, event, serialized_event) - end + specify "calls subscribed class" do + expect(HandlerClass).to receive(:new).and_return(handler) + expect(handler).to receive(:call).with(event) + Dispatcher.new.call(HandlerClass, event, serialized_event) + end - specify "allows callable classes and instances" do - expect(Dispatcher.new.verify(HandlerClass)).to eq(true) - expect(Dispatcher.new.verify(HandlerClass.new)).to eq(true) - expect(Dispatcher.new.verify(Proc.new{ "yo" })).to eq(true) - end + specify "allows callable classes and instances" do + expect(Dispatcher.new.verify(HandlerClass)).to eq(true) + expect(Dispatcher.new.verify(HandlerClass.new)).to eq(true) + expect(Dispatcher.new.verify(Proc.new{ "yo" })).to eq(true) + end - private + private - class HandlerClass - @@received = nil - def self.received - @@received - end - def call(event) - @@received = event - end + class HandlerClass + @@received = nil + def self.received + @@received + end + def call(event) + @@received = event end end end diff --git a/ruby_event_store/spec/instrumented_dispatcher_spec.rb b/ruby_event_store/spec/instrumented_dispatcher_spec.rb index de7a488898..f5bb07152e 100644 --- a/ruby_event_store/spec/instrumented_dispatcher_spec.rb +++ b/ruby_event_store/spec/instrumented_dispatcher_spec.rb @@ -4,7 +4,7 @@ module RubyEventStore RSpec.describe InstrumentedDispatcher do - it_behaves_like :dispatcher, InstrumentedDispatcher.new(PubSub::Dispatcher.new, ActiveSupport::Notifications) + it_behaves_like :dispatcher, InstrumentedDispatcher.new(Dispatcher.new, ActiveSupport::Notifications) describe "#call" do specify "wraps around original implementation" do diff --git a/ruby_event_store/spec/pub_sub_spec.rb b/ruby_event_store/spec/pub_sub_spec.rb new file mode 100644 index 0000000000..c69b303751 --- /dev/null +++ b/ruby_event_store/spec/pub_sub_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +module RubyEventStore + RSpec.describe PubSub do + describe "Subscriptions" do + specify do + expect{RubyEventStore::PubSub::Subscriptions}.to output(<<~MSG).to_stderr + `RubyEventStore::PubSub::Subscriptions` has been deprecated. Use `RubyEventStore::Subscriptions` instead. + MSG + end + + specify do + silence_warnings { expect(PubSub::Subscriptions).to eq(Subscriptions) } + end + end + + describe "Broker" do + specify do + expect{RubyEventStore::PubSub::Broker}.to output(<<~MSG).to_stderr + `RubyEventStore::PubSub::Broker` has been deprecated. Use `RubyEventStore::Broker` instead. + MSG + end + + specify do + silence_warnings { expect(PubSub::Broker).to eq(Broker) } + end + end + + describe "Dispatcher" do + specify do + expect{RubyEventStore::PubSub::Dispatcher}.to output(<<~MSG).to_stderr + `RubyEventStore::PubSub::Dispatcher` has been deprecated. Use `RubyEventStore::Dispatcher` instead. + MSG + end + + specify do + silence_warnings { expect(PubSub::Dispatcher).to eq(Dispatcher) } + end + end + + specify do + expect { PubSub::NoSuchConst }.to raise_error(NameError) + end + end +end diff --git a/ruby_event_store/spec/subscriptions_spec.rb b/ruby_event_store/spec/subscriptions_spec.rb index c5477ee8d0..070e43a3fe 100644 --- a/ruby_event_store/spec/subscriptions_spec.rb +++ b/ruby_event_store/spec/subscriptions_spec.rb @@ -2,9 +2,7 @@ require 'ruby_event_store/spec/subscriptions_lint' module RubyEventStore - module PubSub - RSpec.describe Subscriptions do - it_behaves_like :subscriptions, Subscriptions - end + RSpec.describe Subscriptions do + it_behaves_like :subscriptions, Subscriptions end end