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

RFC: Nested failures fail, not raise #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion lib/interactor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ def run
run!
rescue Failure => e
if context.object_id != e.context.object_id
raise
@context = e.context
end
@context.failure = true
end

# Internal: Invoke an Interactor instance along with all defined hooks. The
Expand Down
24 changes: 24 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,30 @@ def rollback
end
end

context "when a nested call! fails in an interactor" do
let(:interactor3) {
build_interactor do
class NestedInteractor
include Interactor

def call
context.fail!(something: :went_wrong)
end
end

def call
NestedInteractor.call!
end
end
}

it 'sets the failure status on enclosing interactor' do
result = interactor3.call

expect(result.failure?).to eq(true)
end
end

context "when a nested call errors" do
let(:interactor3) {
build_interactor do
Expand Down
8 changes: 0 additions & 8 deletions spec/support/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,6 @@
}.not_to raise_error
end

it "raises other failures" do
expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(Interactor::Context.new))

expect {
instance.run
}.to raise_error(Interactor::Failure)
end

it "raises other errors" do
expect(instance).to receive(:run!).and_raise("foo")

Expand Down