diff --git a/lib/interactor.rb b/lib/interactor.rb index 2423630..307234c 100644 --- a/lib/interactor.rb +++ b/lib/interactor.rb @@ -113,7 +113,10 @@ def initialize(context = {}) # Returns nothing. def run run! - rescue Failure + rescue Failure => e + if context.object_id != e.context.object_id + raise + end end # Internal: Invoke an Interactor instance along with all defined hooks. The diff --git a/spec/support/lint.rb b/spec/support/lint.rb index bfbc97c..55b84d5 100644 --- a/spec/support/lint.rb +++ b/spec/support/lint.rb @@ -70,14 +70,22 @@ instance.run end - it "rescues failure" do - expect(instance).to receive(:run!).and_raise(Interactor::Failure) + it "rescues failure with the same context" do + expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(instance.context)) expect { instance.run }.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")