diff --git a/lib/service_actor/failure.rb b/lib/service_actor/failure.rb index 0db3bff..0f9d6bd 100644 --- a/lib/service_actor/failure.rb +++ b/lib/service_actor/failure.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Error raised when using `fail!` inside an actor. +# Default error raised when using `fail!` inside an actor. class ServiceActor::Failure < ServiceActor::Error def initialize(result) @result = result diff --git a/spec/actor_spec.rb b/spec/actor_spec.rb index d4c01c8..2e35d78 100644 --- a/spec/actor_spec.rb +++ b/spec/actor_spec.rb @@ -1,5 +1,17 @@ # frozen_string_literal: true +CustomArgumentError = Class.new(StandardError) + +class CustomFailureError < StandardError + attr_reader :result + + def initialize(result) + @result = result + + super("Custom failure") + end +end + RSpec.describe Actor do shared_context "with mocked `Kernel.warn` method" do before { allow(Kernel).to receive(:warn).with(kind_of(String)) } @@ -1441,4 +1453,22 @@ def match_result(result) expect(HandleInputCalledError.call(error: "A message")).to be_a_success end end + + context "when calling result with fail_on" do + let(:actor) do + Class.new(Actor) do + fail_on CustomArgumentError + self.argument_error_class = CustomArgumentError + self.failure_class = CustomFailureError + + input :value, type: Integer + end + end + + it "does not raise" do + result = actor.result(value: "boop") + expect(result).to be_a_failure + expect(result.error).to start_with('The "value" input on') + end + end end