sequent icon indicating copy to clipboard operation
sequent copied to clipboard

command_helpers and workflow_helpers conflict

Open yanovitchsky opened this issue 5 years ago • 4 comments

Hello in the sequent spec helper when adding the workflow helpers it seems like the command helpers do not work anymore. the method then_events always return an empty array

RSpec.configure do |config|
  config.include Sequent::Test::WorkflowHelpers
  config.include Sequent::Test::CommandHandlerHelpers
end

As a workaround, I added a rspec configure block in the workflow spec

yanovitchsky avatar Jan 08 '20 08:01 yanovitchsky

Thanks for reporting. Will look into this coming days.

lvonk avatar Jan 10 '20 16:01 lvonk

The WorkflowHelpers need to use the FakeCommandService and register it in the Sequent config. So we need to somehow detect which spec WorkflowHelpers and which needs the CommandHandlerHelpers.

So we can:

  1. document that the WorkflowHelpers can only be used in single specs.
  2. we can include the WorkflowHelpers by using a tag:
describe SendMailWorkflow, :use_workflow_helpers do
  it 'will only include Sequent::Test::WorkflowHelpers if the tag use_workflow_helpers is used'
end

My preference has 2. What's your preference?

lvonk avatar Jan 31 '20 12:01 lvonk

There is another problem that fake command service from workflows helpers are leaking to other specs prevent commands from being executed, and as a result makes tests fail. It's kinda hard to spot because it not always reproducible(it happens only if your workflow specs were run before your command handler ones). To temporarily solve this issue, I added

  before :each do
    .......
    Sequent.configuration.command_service = Sequent::Core::CommandService.new
    .......
  end

@lvonk I probably can make a PR on this(not sure about solution yet tho), would you be interested?

gen1321 avatar Jan 07 '22 05:01 gen1321

Yes that would be nice. Although I think we should solve the conflicting WorkflowHelpers and CommandHandlerHelpers at the same time. We could have something like this (like in EventHandlerHelpers:

around :each, :some_tag do |spec|
  old_config = Sequent.configuration
  Sequent::Configuration.reset
  # set fake command store
  spec.run
ensure
  Sequent::Configuration.restore(old_config)
end

lvonk avatar Jan 07 '22 08:01 lvonk