Replies: 2 comments 4 replies
-
Hello @krisleech, nice to meet you!
Then you can invoke
You should be able to set up them again by calling |
Beta Was this translation helpful? Give feedback.
-
An alternative approach might be to explicitly subscribe in tests. Have each test running with new event store instance that has to be configured beforehand. This works well when you already clear boundaries in the application. Example: module SampleApp
class Configuration
def call(event_store, command_bus)
[
Banking::Configuration.new, # subscriptions in the Banking context
Accounting::Configuration.new,
Cashflow::Configuration.new,
Analytics::Configuration.new,
Crm::Configuration.new
].each { |module_config| module_config.call(event_store, command_bus) }
end
end
end
class ActiveSupport::TestCase
def command_bus
Rails.configuration.command_bus
end
def event_store
Rails.configuration.event_store
end
def replace_event_store_and_command_bus
Rails.configuration.command_bus = Infra::CommandBus.new
Rails.configuration.event_store = Infra::EventStore.new
end
def integrate_with_accounting
Accounting::Configuration.new.call(event_store, command_bus)
end
def integrate_with_cashflow
Cashflow::Configuration.new.call(event_store, command_bus)
end
# ...
end
module Accounting
class TestCase < ActiveSupport::TestCase # each test in accounting has accounting handlers subscribed
def before_setup
super
replace_event_store_and_command_bus
integrate_with_accounting
end
end
end
module Accounting
class RebuildFromScratchTest < TestCase
def test_something_with_integration_of_cashflow_module
integrate_with_cashflow # additionally integrate with cashflow module for "integration" of two contexts
# ...
end
end
end |
Beta Was this translation helpful? Give feedback.
-
I'm working on some legacy code which I'm trying to clean up a bit. We subscribe in a Rails initializer. In some specs we need to have only a subset of subscribers enabled. The way it works now is effectively this:
We have done some refactoring and now we have our own object which wraps
RailsEventStore::Client
, it's something like:What I'd like it a way to temporarily unsubscribe all subscribers, so in the specs we can do something like:
I was thinking doing the following, thought I'd share:
Instead of using
Rails.configuration.event_store
we doEventKit.event.store
.Any comments, thoughts, alternatives welcome 😄
Beta Was this translation helpful? Give feedback.
All reactions