diff --git a/lib/aasm/core/invokers/class_invoker.rb b/lib/aasm/core/invokers/class_invoker.rb index 2f16840..4491052 100644 --- a/lib/aasm/core/invokers/class_invoker.rb +++ b/lib/aasm/core/invokers/class_invoker.rb @@ -17,7 +17,7 @@ module AASM end def invoke_subject - @result = retrieve_instance.call + @result = instance.call end private diff --git a/spec/unit/invokers/class_invoker_spec.rb b/spec/unit/invokers/class_invoker_spec.rb index 63a93e4..7e4f0f0 100644 --- a/spec/unit/invokers/class_invoker_spec.rb +++ b/spec/unit/invokers/class_invoker_spec.rb @@ -52,6 +52,18 @@ describe AASM::Core::Invokers::ClassInvoker do expect(subject.failures.first).to be_a(Method) end + + context 'when a failure occurs' do + let(:target) { Class.new { def initialize(_r, *_a); end; def call; end } } + + it 'only instantiates subject class one time' do + target_instance = target.new(record, *args) + + expect(target).to receive(:new).with(record, *args).and_return(target_instance).once + + expect { subject.invoke }.not_to raise_error + end + end end end