Skip to content

Instantly share code, notes, and snippets.

@jnewland
Created June 6, 2011 22:49
Show Gist options
  • Select an option

  • Save jnewland/1011291 to your computer and use it in GitHub Desktop.

Select an option

Save jnewland/1011291 to your computer and use it in GitHub Desktop.
get the latest installed version of a gem without deprecation warnings
bundle exec rspec spec/rubygems/util_spec.rb 
Bundling your gems. This may take a few minutes on first run.
............................

Finished in 10.89 seconds
28 examples, 0 failures
source :rubygems
gem 'rspec'
gem 'aruba', :require => 'aruba/api'
gem 'test-construct', :require => 'construct'
module Gem::Util
def self.latest_installed_version(name)
begin
if Gem::Specification.respond_to?(:find_by_name)
Gem::Specification.find_by_name(name).version.to_s
else
Gem::SourceIndex.from_installed_gems.find_name(name).last.version.to_s
end
rescue Gem::LoadError, NoMethodError
nil
end
end
end
require "bundler/setup"
Bundler.require
# These versions seem to be missing from
# http://production.cf.rubygems.org/rubygems/rubygems-#{rubygems_version}.tgz
#
# 1.8.0
# 1.8.1
# 1.8.2
# 1.8.3
# 1.8.4
%w{
1.3.7
1.4.0
1.4.1
1.4.2
1.5.0
1.5.1
1.5.2
1.6.0
1.6.1
1.6.2
1.7.0
1.7.1
1.7.2
1.8.5
}.each do |rubygems_version|
describe "rubygems #{rubygems_version}" do
include Construct::Helpers
include Aruba::Api
it "is installable" do
run_simple "wget -q http://production.cf.rubygems.org/rubygems/rubygems-#{rubygems_version}.tgz -O rubygems-#{rubygems_version}.tgz"
run_simple "tar zxvf rubygems-#{rubygems_version}.tgz"
cd "rubygems-#{rubygems_version}"
# need --disable-gems if 1.9?
run_simple "ruby setup.rb"
end
context "can lookup versions" do
it "without deprecation warnings" do
unset_bundler_env_vars
run "ruby -rrubygems /home/rails/rubygems_version_spec/lib/rubygems/util.rb -e \"puts Gem::Util.latest_installed_version('rails')\""
fail all_output if all_output.to_s =~ /deprecated/
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment