Remove duplicated code in allocator spec