Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Disable rubygems more fully when unlocked

Replaces both Gem.path and Gem.source_index with bundled counterparts
  • Loading branch information...
commit 9ef6aa6ead9ed3005b9a7359405f993ba04b03b5 1 parent 5ef7519
André Arko indirect authored
6 lib/bundler.rb
View
@@ -145,16 +145,16 @@ def with_clean_env
ENV.replace(bundled_env.to_hash)
end
- private
-
def default_gemfile
SharedHelpers.default_gemfile
end
+ private
+
def configure_gem_home_and_path
if settings[:disable_shared_gems]
- ENV['GEM_HOME'] = File.expand_path(bundle_path, root)
ENV['GEM_PATH'] = ''
+ ENV['GEM_HOME'] = File.expand_path(bundle_path, root)
else
paths = [Gem.dir, Gem.path].flatten.compact.uniq.reject{|p| p.empty? }
ENV["GEM_PATH"] = paths.join(File::PATH_SEPARATOR)
14 lib/bundler/runtime.rb
View
@@ -18,6 +18,7 @@ def setup(*groups)
specs = groups.any? ? specs_for(groups) : requested_specs
cripple_rubygems(specs)
+ replace_rubygems_paths
# Activate the specs
specs.each do |spec|
@@ -126,5 +127,18 @@ def details
end
details
end
+
+ def replace_rubygems_paths
+ Gem.instance_eval do
+ def path
+ [Bundler.bundle_path.to_s]
+ end
+
+ def source_index
+ @source_index ||= Gem::SourceIndex.from_installed_gems
+ end
+ end
+ end
+
end
end
4 lib/bundler/shared_helpers.rb
View
@@ -72,12 +72,12 @@ def cripple_rubygems(specs)
reverse_rubygems_kernel_mixin
executables = specs.map { |s| s.executables }.flatten
+ Gem.source_index # ensure RubyGems is fully loaded
- :: Kernel.class_eval do
+ ::Kernel.class_eval do
private
def gem(*) ; end
end
- Gem.source_index # ensure RubyGems is fully loaded
::Kernel.send(:define_method, :gem) do |dep, *reqs|
if executables.include? File.basename(caller.first.split(':').first)
75 spec/runtime/setup_spec.rb
View
@@ -32,40 +32,59 @@
end
describe "cripping rubygems" do
- it "replaces #gem with an alternative that raises when appropriate" do
- install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
- G
+ describe "by replacing #gem" do
+ before :each do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack", "0.9.1"
+ G
+ end
- run <<-R
- begin
- gem "activesupport"
- puts "FAIL"
- rescue LoadError
- puts "WIN"
- end
- R
+ it "replaces #gem but raises when the gem is missing" do
+ run <<-R
+ begin
+ gem "activesupport"
+ puts "FAIL"
+ rescue LoadError
+ puts "WIN"
+ end
+ R
+
+ out.should == "WIN"
+ end
- out.should == "WIN"
+ it "replaces #gem but raises when the version is wrong" do
+ run <<-R
+ begin
+ gem "rack", "1.0.0"
+ puts "FAIL"
+ rescue LoadError
+ puts "WIN"
+ end
+ R
+
+ out.should == "WIN"
+ end
end
- it "replaces #gem with an alternative that raises when appropriate 2" do
- install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack", "0.9.1"
- G
+ describe "by hiding system gems" do
+ before :each do
+ system_gems "activesupport-2.3.5"
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "yard"
+ G
+ end
- run <<-R
- begin
- gem "rack", "1.0.0"
- puts "FAIL"
- rescue LoadError
- puts "WIN"
- end
- R
+ it "removes system gem repositories from Gem.path" do
+ run "puts Gem.path.join('\n')"
+ out.should == Bundler.bundle_path.to_s
+ end
- out.should == "WIN"
+ it "removes system gems from Gem.source_index" do
+ run "require 'yard'"
+ err.should be_empty
+ end
end
end
8 spec/support/builders.rb
View
@@ -122,6 +122,14 @@ def build_repo1
s.write "lib/rubygems_plugin.rb", "require 'bundler/omg' ; puts 'FAIL'"
end
+ build_gem "yard" do |s|
+ s.write "lib/yard.rb", <<-Y
+ Gem.source_index.find_name('').each do |gem|
+ require gem.name
+ end
+ Y
+ end
+
# Test comlicated gem dependencies for install
build_gem "net_a" do |s|
s.add_dependency "net_b"
Please sign in to comment.
Something went wrong with that request. Please try again.