Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add `each` step to service framework for collection iteration (#38759)

Loïc Guitaut3ed866a6c98d
diff --git a/docs/developer-guides/docs/03-code-internals/19-service-objects.md b/docs/developer-guides/docs/03-code-internals/19-service-objects.md
index d4e71df1ae8..948ecce8762 100644
--- a/docs/developer-guides/docs/03-code-internals/19-service-objects.md
+++ b/docs/developer-guides/docs/03-code-internals/19-service-objects.md
@@ -148,6 +148,14 @@ This step is another special one, as it’s similar to a contract (without the v
This step will only run the steps defined in its block if the provided condition is true. That’s another step that can’t fail by itself.
+### `each`
+
+This step iterates over a collection from the context and runs the steps defined in its block for each item. The item is provided under its singularized name (e.g., `each :users` provides `user:`) along with `index:`. If any nested step fails, iteration stops immediately and the service fails with the failing item and index available in context.
+
+An empty collection is silently skipped.
+
+A `persist:` option allows values to accumulate across iterations and survive the loop’s variable isolation. This is useful for collecting results during bulk operations.
+
### Steps arguments
Each step is called with the service context. To access a value in it, just provide its key as a keyword argument.
@@ -412,6 +420,41 @@ This step wraps other steps. If the condition is not met (meaning the related me
That step is very useful when you have several steps depending on the same condition to be run, as it allows to keep all the error handling provided by steps like `model`, `policy`, etc.
+### `each(collection_name, as: nil, persist: nil, &block)`
+
+**Arguments**
+
+- _collection_name_: the name of the context key holding the collection to iterate over.
+- _as_: override the singularized item name. For example, `each :users, as: :member` provides `member:` instead of `user:`.
+- _persist_: keys that should accumulate across iterations and survive the loop's variable isolation. Accepts a hash where values are lambdas or method symbols used to initialize the key, or an array of symbols for keys without initialization.
+- _block_: a block containing other steps.
+
+This step iterates over a collection and runs the steps defined in its block for each item. Each iteration receives the singularized item name (e.g., `user:` for `each :users`) and `index:` as keyword arguments.
+
+By default, variables set inside the loop are isolated: they don't leak to the outer context. The `persist:` option allows specific keys to survive the isolation. This is particularly useful for accumulating results during bulk operations.
+
+If any nested step fails (a policy returns falsy, a model is not found, or `fail!` is called), iteration stops immediately and the service fails. The failing item and index remain available in context for error reporting, and existing matchers (`on_failed_policy`, `on_model_not_found`, etc.) work as expected.
+
+An empty collection is silently skipped.
+
+```rb
+# Fail-fast iteration
+each :users do
+ policy :can_delete
+ step :destroy
+end
+
+# Accumulating results across iterations
+each :tag_names, persist: { results: -> { { created: [], failed: [] } } } do
+ step :create_tag
+end
+
+# Custom item name
+each :users, as: :target_user do
+ step :process
+end
+```
+
### `step(name)`
**Arguments**
diff --git a/lib/service/base.rb b/lib/service/base.rb
index 5f6842604bf..338f4985dee 100644
--- a/lib/service/base.rb
+++ b/lib/service/base.rb
@@ -174,6 +174,28 @@
# # step :update_post
# # step :log_post_update
# # end
+#
+# # @!scope class
+# # @!method each(collection_name, as: nil, persist: nil, &block)
+# # @param collection_name [Symbol] the name of the context key holding the collection
+# # @param as [Symbol] override the singularized item name
+# # @param persist [Hash, Array, Symbol] keys that accumulate across iterations
+# # @param block [Proc] a block containing steps to run for each item
+# # Iterates over a collection and runs nested steps for each item.
+# # The singularized item name and +index+ are provided as keyword
+# # arguments. Iteration stops on first failure. Variables set inside
+# # the loop are isolated unless listed in +persist+.
+# #
+# # @example basic iteration
+# # each :users do
+# # policy :can_delete
+# # step :destroy
+# # end
+# #
+# # @example accumulating results
+# # each :tag_names, persist: { results: -> { [] } } do
+# # step :create_tag
+# # end
# end
module Service
diff --git a/lib/service/base/context.rb b/lib/service/base/context.rb
index 16ac4339e22..71700514fbd 100644
--- a/lib/service/base/context.rb
+++ b/lib/service/base/context.rb
@@ -4,7 +4,7 @@ module Service
module Base
# Simple structure to hold the context of the service during its whole lifecycle.
class Context
- delegate :slice, :dig, to: :store
+ delegate :slice, :dig, :merge!, to: :store
def self.build(context = {})
self === context ? context : new(context)
@@ -23,7 +23,15 @@ module Service
end
def to_h
- store.dup
+ store.deep_dup
+ end
+
+ def with_isolation(persist_keys: [])
+ @isolated_store = to_h
+ yield
+ ensure
+ @store.merge!(@isolated_store.slice(*persist_keys, *step_result_keys))
+ @isolated_store = nil
end
# @return [Boolean] returns +true+ if the context is set as successful (default)
@@ -65,7 +73,13 @@ module Service
private
- attr_reader :store
+ def store
+ @isolated_store || @store
+ end
+
+ def step_result_keys
+ store.keys.select { it.start_with?("result.") }
+ end
def method_missing(method_name, *args, &block)
return super if args.present?
diff --git a/lib/service/base/each_step.rb b/lib/service/base/each_step.rb
new file mode 100644
index 00000000000..d6141a3fea9
--- /dev/null
+++ b/lib/service/base/each_step.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+module Service
+ module Base
+ class EachStep < Step
+ include StepsHelpers
+
+ attr_reader :steps, :item_name, :initializers
+
+ def initialize(name, as: nil, persist: nil, &block)
+ super(name)
+ @item_name = as || name.to_s.singularize.to_sym
+ @initializers = build_initializers(persist)
+ @steps = []
+ instance_exec(&block)
+ end
+
+ def run_step
+ context.with_isolation(persist_keys: [item_name, :index, *initializers.keys]) do
+ context.merge!(initializers.transform_values { instance.instance_exec(&it) })
+ Array
+ .wrap(context[name])
+ .tap do |collection|
+ context[result_key].merge!(total: collection.size, skipped?: collection.empty?)
+ end
+ .each_with_index do |item, index|
+ context.merge!(item_name => item, :index => index)
+ steps.each { |step| step.call(instance, context) }
+ end
+ end
+ end
+
+ private
+
+ def build_initializers(value)
+ case value
+ when nil
+ {}
+ when Array
+ value.each_with_object({}) { |item, hash| hash.merge!(build_initializers(item)) }
+ when Symbol
+ { value => proc {} }
+ when Hash
+ value.transform_values(&method(:make_lambda))
+ end
+ end
+
+ def make_lambda(filter)
+ case filter
+ when Symbol
+ proc { send(filter) }
+ when Proc
+ proc { instance_exec(&filter) }
+ else
+ proc {}
+ end
+ end
+ end
+ end
+end
diff --git a/lib/service/base/steps_helpers.rb b/lib/service/base/steps_helpers.rb
index 2b0e5240e04..f2f8407d7cc 100644
--- a/lib/service/base/steps_helpers.rb
+++ b/lib/service/base/steps_helpers.rb
@@ -49,6 +49,10 @@ module Service
def only_if(name, &block)
steps << OnlyIfStep.new(name, &block)
end
+
+ def each(collection_name, as: nil, persist: nil, &block)
+ steps << EachStep.new(collection_name, as:, persist:, &block)
+ end
end
end
end
diff --git a/lib/service/steps_inspector.rb b/lib/service/steps_inspector.rb
index fa195777622..6c51031bb61 100644
--- a/lib/service/steps_inspector.rb
+++ b/lib/service/steps_inspector.rb
@@ -187,6 +187,25 @@ class Service::StepsInspector
end
end
+ # @!visibility private
+ class Each < OnlyIf
+ def inspect
+ "#{" " * nesting_level}\e[#{ansi_color}m[#{inspect_type}] #{name} (#{iteration_info})#{runtime}\e[0m #{skipped_emoji}".rstrip
+ end
+
+ private
+
+ def iteration_info
+ return "empty collection" if skipped?
+ "#{result[:index].to_i + 1}/#{step_result[:total].to_i}"
+ end
+
+ def skipped_emoji
+ return unless skipped?
+ emoji
+ end
+ end
+
attr_reader :steps, :result
def initialize(result)
diff --git a/spec/lib/service/base/each_step_spec.rb b/spec/lib/service/base/each_step_spec.rb
new file mode 100644
index 00000000000..dbc07822c25
--- /dev/null
+++ b/spec/lib/service/base/each_step_spec.rb
@@ -0,0 +1,200 @@
+# frozen_string_literal: true
+
+RSpec.describe Service::Base::EachStep do
+ describe "#call" do
+ subject(:result) { service.call(dependencies) }
+
+ let(:dependencies) { {} }
+
+ context "when iterating over a collection" do
+ let(:service) do
+ Class.new do
+ include Service::Base
+
+ model :users
+
+ each :users, persist: { processed: -> { [] } } do
+ step :process_user
+ end
+
+ step :finalize
+
+ private
+
+ def fetch_users
+ context[:input_users]
+ end
+
+ def process_user(user:, index:, processed:)
+ processed << { user:, index: }
+ end
+
+ def finalize
+ context[:finalized] = true
+ end
+ end
+ end
+ let(:dependencies) { { input_users: %i[alice bob charlie] } }
+
+ it { is_expected.to run_successfully }
+
+ it "provides each item under the singularized name and its index" do
+ expect(result[:processed]).to contain_exactly(
+ { user: :alice, index: 0 },
+ { user: :bob, index: 1 },
+ { user: :charlie, index: 2 },
+ )
+ end
+
+ it "continues to subsequent steps after iteration" do
+ expect(result[:finalized]).to be true
+ end
+ end
+
+ context "when using the as: option" do
+ let(:service) do
+ Class.new do
+ include Service::Base
+
+ model :users
+
+ each :users, as: :member, persist: { processed: -> { [] } } do
+ step :process_member
+ end
+
+ private
+
+ def fetch_users
+ context[:input_users]
+ end
+
+ def process_member(member:, processed:)
+ processed << member
+ end
+ end
+ end
+ let(:dependencies) { { input_users: %i[alice bob] } }
+
+ it "provides items under the custom name" do
+ expect(result[:processed]).to contain_exactly(:alice, :bob)
+ end
+ end
+
+ context "with variable isolation" do
+ let(:service) do
+ Class.new do
+ include Service::Base
+
+ step :setup
+
+ each :users do
+ model :profile
+ step :track
+ end
+
+ step :check_after
+
+ private
+
+ def setup
+ context[:users] = %i[alice bob]
+ context[:existing_value] = "original"
+ end
+
+ def fetch_profile(user:)
+ "#{user}_profile"
+ end
+
+ def track(user:)
+ context[:set_inside_loop] = user
+ end
+
+ def check_after
+ context[:profile_after] = context[:profile]
+ context[:user_after] = context[:user]
+ context[:index_after] = context[:index]
+ context[:set_inside_after] = context[:set_inside_loop]
+ context[:existing_after] = context[:existing_value]
+ end
+ end
+ end
+
+ it "discards non-persisted variables set inside the loop" do
+ expect(result).to have_attributes(profile_after: nil, set_inside_after: nil)
+ end
+
+ it "keeps the last item and index after the loop" do
+ expect(result).to have_attributes(user_after: :bob, index_after: 1)
+ end
+
+ it "restores pre-existing values after the loop" do
+ expect(result).to have_attributes(existing_after: "original")
+ end
+ end
+
+ context "with persist option" do
+ context "with a lambda initializer" do
+ let(:service) do
+ Class.new do
+ include Service::Base
+
+ model :users
+
+ each :users, persist: { results: -> { { created: [], failed: [] } } } do
+ step :process_user
+ end
+
+ private
+
+ def fetch_users
+ context[:input_users]
+ end
+
+ def process_user(user:, results:)
+ user == :invalid ? results[:failed] << user : results[:created] << user
+ end
+ end
+ end
+ let(:dependencies) { { input_users: %i[alice invalid bob] } }
+
+ it "initializes and accumulates across iterations" do
+ expect(result[:results]).to eq(created: %i[alice bob], failed: [:invalid])
+ end
+ end
+
+ context "with a method symbol initializer" do
+ let(:service) do
+ Class.new do
+ include Service::Base
+
+ model :users
+
+ each :users, persist: { results: :initial_results } do
+ step :process_user
+ end
+
+ private
+
+ def fetch_users
+ context[:input_users]
+ end
+
+ def initial_results
+ { processed: [], count: 0 }
+ end
+
+ def process_user(user:, results:)
+ results[:processed] << user
+ results[:count] += 1
+ end
+ end
+ end
+ let(:dependencies) { { input_users: %i[alice bob] } }
+
+ it "initializes by calling the method" do
+ expect(result[:results]).to eq(processed: %i[alice bob], count: 2)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/service/steps_inspector_spec.rb b/spec/lib/service/steps_inspector_spec.rb
index 79db5aa6f59..264072b1a1c 100644
--- a/spec/lib/service/steps_inspector_spec.rb
+++ b/spec/lib/service/steps_inspector_spec.rb
@@ -28,13 +28,20 @@ RSpec.describe Service::StepsInspector do
try { step :might_raise }
only_if(:condition) { step :optional_step }
+
+ each :things do
+ step :in_each_step_1
+ step :in_each_step_2
+ end
+
step :final_step
end
subject(:inspector) { described_class.new(result) }
let(:parameter) { "present" }
- let(:result) { DummyService.call(params: { parameter: }) }
+ let(:result) { DummyService.call(params: { parameter: }, things:) }
+ let(:things) { %i[item_1 item_2 item_3] }
before do
class DummyService
@@ -46,6 +53,8 @@ RSpec.describe Service::StepsInspector do
might_raise
condition
optional_step
+ in_each_step_1
+ in_each_step_2
final_step
].each { |name| define_method(name) { true } }
end
@@ -59,19 +68,22 @@ RSpec.describe Service::StepsInspector do
context "when service runs without error" do
it "outputs all the steps of the service" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ✅
- [ 6/13] [transaction]
- [ 7/13] [step] in_transaction_step_1 ✅
- [ 8/13] [step] in_transaction_step_2 ✅
- [ 9/13] [try]
- [10/13] [step] might_raise ✅
- [11/13] [only_if] condition ✅
- [12/13] [step] optional_step ✅
- [13/13] [step] final_step ✅
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise ✅
+ [11/16] [only_if] condition ✅
+ [12/16] [step] optional_step ✅
+ [13/16] [each] things (3/3)
+ [14/16] [step] in_each_step_1 ✅
+ [15/16] [step] in_each_step_2 ✅
+ [16/16] [step] final_step ✅
OUTPUT
end
@@ -91,10 +103,10 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ❌
- (11 more steps not shown as the execution flow was stopped before reaching them)
+ (14 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -110,11 +122,11 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ❌
- (10 more steps not shown as the execution flow was stopped before reaching them)
+ (13 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -124,12 +136,12 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ❌
- (9 more steps not shown as the execution flow was stopped before reaching them)
+ (12 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -145,16 +157,16 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ✅
- [ 6/13] [transaction]
- [ 7/13] [step] in_transaction_step_1 ✅
- [ 8/13] [step] in_transaction_step_2 ❌
-
- (5 more steps not shown as the execution flow was stopped before reaching them)
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ❌
+
+ (8 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -170,18 +182,18 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ✅
- [ 6/13] [transaction]
- [ 7/13] [step] in_transaction_step_1 ✅
- [ 8/13] [step] in_transaction_step_2 ✅
- [ 9/13] [try]
- [10/13] [step] might_raise 💥
-
- (3 more steps not shown as the execution flow was stopped before reaching them)
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise 💥
+
+ (6 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -191,13 +203,13 @@ RSpec.describe Service::StepsInspector do
it "shows the failing step" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ❌
- (8 more steps not shown as the execution flow was stopped before reaching them)
+ (11 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -213,19 +225,79 @@ RSpec.describe Service::StepsInspector do
it "shows the block was skipped" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ✅
- [ 6/13] [transaction]
- [ 7/13] [step] in_transaction_step_1 ✅
- [ 8/13] [step] in_transaction_step_2 ✅
- [ 9/13] [try]
- [10/13] [step] might_raise ✅
- [11/13] [only_if] condition ⏭️ (condition was not met)
- [12/13] [step] optional_step
- [13/13] [step] final_step ✅
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise ✅
+ [11/16] [only_if] condition ⏭️ (condition was not met)
+ [12/16] [step] optional_step
+ [13/16] [each] things (3/3)
+ [14/16] [step] in_each_step_1 ✅
+ [15/16] [step] in_each_step_2 ✅
+ [16/16] [step] final_step ✅
+ OUTPUT
+ end
+ end
+
+ context "when a step inside the each block is failing" do
+ before do
+ class DummyService
+ def in_each_step_2(thing:)
+ fail!("error on #{thing}")
+ end
+ end
+ end
+
+ it "shows the failing step inside the each block" do
+ expect(output).to eq <<~OUTPUT.chomp
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise ✅
+ [11/16] [only_if] condition ✅
+ [12/16] [step] optional_step ✅
+ [13/16] [each] things (1/3)
+ [14/16] [step] in_each_step_1 ✅
+ [15/16] [step] in_each_step_2 ❌
+
+ (1 more steps not shown as the execution flow was stopped before reaching them)
+ OUTPUT
+ end
+ end
+
+ context "when the each block has no items" do
+ let(:things) { [] }
+
+ it "shows the each block was skipped" do
+ expect(output).to eq <<~OUTPUT.chomp
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise ✅
+ [11/16] [only_if] condition ✅
+ [12/16] [step] optional_step ✅
+ [13/16] [each] things (empty collection) ⏭️
+ [14/16] [step] in_each_step_1
+ [15/16] [step] in_each_step_2
+ [16/16] [step] final_step ✅
OUTPUT
end
end
@@ -236,19 +308,22 @@ RSpec.describe Service::StepsInspector do
it "adapts its output accordingly" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅ ⚠️ <= expected to return false but got true instead
- [ 4/13] [params] default ✅
- [ 5/13] [lock] parameter:other_param ✅
- [ 6/13] [transaction]
- [ 7/13] [step] in_transaction_step_1 ✅
- [ 8/13] [step] in_transaction_step_2 ✅
- [ 9/13] [try]
- [10/13] [step] might_raise ✅
- [11/13] [only_if] condition ✅
- [12/13] [step] optional_step ✅
- [13/13] [step] final_step ✅
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅ ⚠️ <= expected to return false but got true instead
+ [ 4/16] [params] default ✅
+ [ 5/16] [lock] parameter:other_param ✅
+ [ 6/16] [transaction]
+ [ 7/16] [step] in_transaction_step_1 ✅
+ [ 8/16] [step] in_transaction_step_2 ✅
+ [ 9/16] [try]
+ [10/16] [step] might_raise ✅
+ [11/16] [only_if] condition ✅
+ [12/16] [step] optional_step ✅
+ [13/16] [each] things (3/3)
+ [14/16] [step] in_each_step_1 ✅
+ [15/16] [step] in_each_step_2 ✅
+ [16/16] [step] final_step ✅
OUTPUT
end
end
@@ -265,11 +340,11 @@ RSpec.describe Service::StepsInspector do
it "adapts its output accordingly" do
expect(output).to eq <<~OUTPUT.chomp
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ❌ ⚠️ <= expected to return true but got false instead
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ❌ ⚠️ <= expected to return true but got false instead
- (10 more steps not shown as the execution flow was stopped before reaching them)
+ (13 more steps not shown as the execution flow was stopped before reaching them)
OUTPUT
end
end
@@ -414,12 +489,12 @@ RSpec.describe Service::StepsInspector do
<<~OUTPUT,
Inspecting DummyService result object:
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ❌
- (9 more steps not shown as the execution flow was stopped before reaching them)
+ (12 more steps not shown as the execution flow was stopped before reaching them)
Why it failed:
@@ -430,12 +505,12 @@ RSpec.describe Service::StepsInspector do
).or eq(<<~OUTPUT)
Inspecting DummyService result object:
- [ 1/13] [options] default ✅
- [ 2/13] [model] model ✅
- [ 3/13] [policy] policy ✅
- [ 4/13] [params] default ❌
+ [ 1/16] [options] default ✅
+ [ 2/16] [model] model ✅
+ [ 3/16] [policy] policy ✅
+ [ 4/16] [params] default ❌
- (9 more steps not shown as the execution flow was stopped before reaching them)
+ (12 more steps not shown as the execution flow was stopped before reaching them)
Why it failed: