# File lib/flexmock/partial_mock.rb, line 130
130:     def new_instances(*allocators, &block)
131:       fail ArgumentError, "new_instances requires a Class to stub" unless Class === @obj
132:       location = caller.first
133:       allocators = [:new] if allocators.empty?
134:       result = ExpectationRecorder.new
135:       allocators.each do |allocate_method|
136:         check_allocate_method(allocate_method)
137:         # HACK: Without the following lambda, Some versions of Ruby 1.9
138:         #       would not bind the allocate_method parameter
139:         #       correctly. I don't think it is necessary for recent
140:         #       versions.
141:         lambda { }
142:         self.flexmock_define_expectation(location, allocate_method).and_return { |*args|
143:           new_obj = invoke_original(allocate_method, args)
144:           mock = flexmock_container.flexmock(new_obj)
145:           block.call(mock) if block_given?
146:           result.apply(mock)
147:           new_obj
148:         }
149:       end
150:       result
151:     end