# frozen_string_literal: truemoduleNextFoundInstanceOfERROR_MESSAGE='NextFoundInstanceOf mock helpers can only be used with ActiveRecord targets'defexpect_next_found_instance_of(klass)check_if_active_record!(klass)stub_allocate(expect(klass))do|expectation|yield(expectation)endenddefallow_next_found_instance_of(klass)check_if_active_record!(klass)stub_allocate(allow(klass))do|allowance|yield(allowance)endendprivatedefcheck_if_active_record!(klass)raiseArgumentError.new(ERROR_MESSAGE)unlessklass<ActiveRecord::Baseenddefstub_allocate(target)target.toreceive(:allocate).and_wrap_originaldo|method|method.call.tap{|allocation|yield(allocation)}endendend