Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra spec to make sure fail_on can work with custom argument_error_class and failure_class 🌌 #165

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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