puppetlabs/puppet — pull request #1423 by joshcooper (2013-01-23 06:17:02+00:00)
Title: (#18755) Consider prerelease gems in the search path

Previously, if puppet 3.0.2 and 3.1.0.rc1 gems were installed using
rubygems version 1.8 or greater, then puppet's autoloader would load
code from both gems, giving precedence to the older gem.

Puppet's settings code was loading the `Puppet::Type::Group` class from
the 3.0.2 gem, but trying to call the `#exists?` method that was added
in 3.1.0rc1, resulting in the "undefined method 'exists?' for nil"
error.

The root cause was due to `Gem::Specification.latest_specs` ignoring
prerelease gems, by default, so it would report that the latest spec was
3.0.2. Yet, executing `require 'puppet'` would activate the prerelease
gem, 3.1.0.rc1, causing its lib dir to be appended to $LOAD_PATH.

And since Puppet's autoloader combines the rubygems directories and
$LOAD_PATH (roughly in that order), version 3.0.2 would take precedence.

Note this issue is specific to rubygems 1.8 and up, since when using
previous versions, puppet calls the deprecated method
`Gem.latest_load_paths`, which alread considers prerelease gems when
determining the latest installed gem.

This commit simply modifies the call to `Gem::Specification.latest_spec`
to consider prerelease gems when determining the latest installed
version.