Skip to content

Mocking Operations #21

@richardboehme

Description

@richardboehme

In some cases one might prefer to mock Operation calls. This might be helpful, when testing Operations that invoke Subprocesses that are not of interest in the test.

One example of doing this can be seen here (using the mocha gem):

signal = Song::Operation::Create.to_h[:outputs].find { |output| output.signal.to_h[:semantic] == :success }.signal
Song::Operation::Create.expects(:call).once.with do |(ctx, _)|
  !ctx[:name].empty? &&
    ctx[:length].to_i > 0
end.returns([signal, Trailblazer::Context({ song: Song.new })])

I believe we could benefit from providing a universial way of defining such expectations. The current way of doing this is kinda complicated:

  • You have to extract the correct signal instance from the operation yourself.
  • There are different call interfaces (when using in Subprocess vs. calling the operations yourself)
  • If you want to mock a Subprocess you have to know the circuit interface

It may be possible to provide a simpler interface which allows:

  • return different signals (by name/class?)
  • expect specific inputs
  • return a specific new context (which might depend on the inputs?) => define outputs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions