Injecting operations

You can inject operation objects into transactions to adjust their behavior at runtime. This could be helpful to substitute operations with test doubles to simulate various conditions in testing.

To inject operation objects, pass them as keyword arguments to the initializer, with their keyword matching the step’s name.

Every injected operation must respond to #call(input, *args).

class CreateUser
  include Dry::Transaction(container: Container)

  step :process, with: "operations.process"
  step :validate, with: "operations.validate"
  step :persist, with: "operations.persist"

substitute_validate_step = -> input { Failure(:definitely_not_valid) }

create_user = substitute_validate_step)"name" => "Jane", "email" => "")
# => Failure(:definitely_not_valid)