Skip to content

Commit

Permalink
Add extra spec to make sure fail_on can work with custom argument_err…
Browse files Browse the repository at this point in the history
…or_class and failure_class 🌌
  • Loading branch information
sunny committed Jul 25, 2024
1 parent 3ff9f88 commit aa8a57c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/service_actor/failure.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/actor_spec.rb
Original file line number Diff line number Diff line change
@@ -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)) }
Expand Down Expand Up @@ -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

0 comments on commit aa8a57c

Please sign in to comment.