Module: Sequent::Test::WorkflowHelpers
- Defined in:
- lib/sequent/test/event_handler_helpers.rb
Overview
Use in tests
This provides a nice DSL for testing your event handlers. E.g.
when_event UserWasRegistered.new(args) then_commands SendWelcomeEmail.new(args)
Example for Rspec config
RSpec.configure do |config|
config.include Sequent::Test::WorkflowHelpers
end
Then in a spec
describe SendWelcomeMailWorkflow do
let(:workflow) { SendWelcomeMailWorkflow.new }
it "sends a welcome mail" do
when_event UserWasRegistered.new(args)
then_commands SendWelcomeEmail.new(args)
end
end
Defined Under Namespace
Classes: FakeCommandService
Class Method Summary collapse
Instance Method Summary collapse
- #then_commands(*commands) ⇒ Object
- #then_events(*events) ⇒ Object
- #then_no_events ⇒ Object
- #when_event(event) ⇒ Object
Class Method Details
.included(spec) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/sequent/test/event_handler_helpers.rb', line 63 def self.included(spec) spec.let(:fake_command_service) { FakeCommandService.new } spec.before do Sequent.configure { |c| c.command_service = fake_command_service } end end |
Instance Method Details
#then_commands(*commands) ⇒ Object
57 58 59 60 61 |
# File 'lib/sequent/test/event_handler_helpers.rb', line 57 def then_commands(*commands) recorded = fake_command_service.recorded_commands expect(recorded.map(&:class)).to eq(commands.flatten(1).map(&:class)) expect(fake_command_service.recorded_commands).to eq(commands.flatten(1)) end |
#then_events(*events) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/sequent/test/event_handler_helpers.rb', line 42 def then_events *events expect(@event_store.stored_events.map(&:class)).to eq(events.flatten(1).map(&:class)) @event_store.stored_events.zip(events.flatten(1)).each do |actual, expected| expect(Sequent::Core::Oj.strict_load(Sequent::Core::Oj.dump(actual.payload))).to eq(Sequent::Core::Oj.strict_load(Sequent::Core::Oj.dump(expected.payload))) if expected end end |
#then_no_events ⇒ Object
49 50 51 |
# File 'lib/sequent/test/event_handler_helpers.rb', line 49 def then_no_events then_events end |
#when_event(event) ⇒ Object
53 54 55 |
# File 'lib/sequent/test/event_handler_helpers.rb', line 53 def when_event(event) workflow. event end |