summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-02-05 14:21:12 -0800
committerCarl Lerche <carllerche@mac.com>2010-02-05 14:35:38 -0800
commit6d369092a8416f43e5a667d1b874bb23a35a16b6 (patch)
tree16b9c0e10f6fc9ae17b270a061d014854e2183ed
parentc66237d7346e97b89978f10952da42418618d447 (diff)
downloadbundler-6d369092a8416f43e5a667d1b874bb23a35a16b6.tar.gz
Cripple rubygems with a smarter #gem
-rw-r--r--bundler.gemspec6
-rw-r--r--lib/bundler/runtime.rb33
-rw-r--r--spec/runtime/setup_spec.rb38
3 files changed, 69 insertions, 8 deletions
diff --git a/bundler.gemspec b/bundler.gemspec
index 89178b80a2..a16a9bec50 100644
--- a/bundler.gemspec
+++ b/bundler.gemspec
@@ -2,15 +2,15 @@
Gem::Specification.new do |s|
s.name = %q{bundler}
- s.version = "0.9.2"
+ s.version = "0.9.3.pre"
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
s.authors = ["Carl Lerche", "Yehuda Katz"]
- s.date = %q{2010-02-04}
+ s.date = %q{2010-02-05}
s.default_executable = %q{bundle}
s.email = ["carlhuda@engineyard.com"]
s.executables = ["bundle"]
- s.files = ["bin/bundle", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/runtime.rb", "lib/bundler/settings.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"]
+ s.files = ["bin/bundle", "lib/bundler", "lib/bundler/cli.rb", "lib/bundler/definition.rb", "lib/bundler/dependency.rb", "lib/bundler/dsl.rb", "lib/bundler/environment.rb", "lib/bundler/index.rb", "lib/bundler/installer.rb", "lib/bundler/remote_specification.rb", "lib/bundler/resolver.rb", "lib/bundler/rubygems.rb", "lib/bundler/runtime.rb", "lib/bundler/settings.rb", "lib/bundler/setup.rb", "lib/bundler/source.rb", "lib/bundler/specification.rb", "lib/bundler/templates", "lib/bundler/templates/environment.erb", "lib/bundler/templates/Gemfile", "lib/bundler/ui.rb", "lib/bundler/vendor", "lib/bundler/vendor/thor", "lib/bundler/vendor/thor/base.rb", "lib/bundler/vendor/thor/core_ext", "lib/bundler/vendor/thor/core_ext/file_binary_read.rb", "lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb", "lib/bundler/vendor/thor/core_ext/ordered_hash.rb", "lib/bundler/vendor/thor/error.rb", "lib/bundler/vendor/thor/invocation.rb", "lib/bundler/vendor/thor/parser", "lib/bundler/vendor/thor/parser/argument.rb", "lib/bundler/vendor/thor/parser/arguments.rb", "lib/bundler/vendor/thor/parser/option.rb", "lib/bundler/vendor/thor/parser/options.rb", "lib/bundler/vendor/thor/parser.rb", "lib/bundler/vendor/thor/shell", "lib/bundler/vendor/thor/shell/basic.rb", "lib/bundler/vendor/thor/shell/color.rb", "lib/bundler/vendor/thor/shell.rb", "lib/bundler/vendor/thor/task.rb", "lib/bundler/vendor/thor/util.rb", "lib/bundler/vendor/thor/version.rb", "lib/bundler/vendor/thor.rb", "lib/bundler.rb", "LICENSE", "README.markdown"]
s.homepage = %q{http://github.com/carlhuda/bundler}
s.post_install_message = %q{Due to a rubygems bug, you must uninstall all older versions of bundler for 0.9 to work}
s.require_paths = ["lib"]
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index 75eaf9b8d3..a39c81703a 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -3,11 +3,12 @@ require "digest/md5"
module Bundler
class Runtime < Environment
def setup(*groups)
+ specs = specs_for(*groups)
# Has to happen first
- cripple_rubygems
+ cripple_rubygems(specs)
# Activate the specs
- specs_for(*groups).each do |spec|
+ specs.each do |spec|
Gem.loaded_specs[spec.name] = spec
$LOAD_PATH.unshift(*spec.load_paths)
end
@@ -118,7 +119,7 @@ module Bundler
specs.map { |s| s.load_paths }.flatten
end
- def cripple_rubygems
+ def cripple_rubygems(specs)
# handle 1.9 where system gems are always on the load path
if defined?(::Gem)
me = File.expand_path("../../", __FILE__)
@@ -138,9 +139,31 @@ module Bundler
end
undef gem
- def gem(*)
- # Silently ignore calls to gem
+ end
+
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
+ opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
+
+ unless dep.respond_to?(:name) && dep.respond_to?(:version_requirements)
+ dep = Gem::Dependency.new(dep, reqs)
end
+
+ spec = specs.find { |s| s.name == dep.name }
+
+ if spec.nil?
+ e = Gem::LoadError.new "#{dep} is not part of the bundle. Add it to Gemfile."
+ e.name = dep.name
+ e.version_requirement = dep.version_requirements
+ raise e
+ elsif dep !~ spec
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
+ "Make sure all dependencies are added to Gemfile."
+ e.name = dep.name
+ e.version_requirement = dep.version_requirements
+ raise e
+ end
+
+ true
end
end
diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb
index c8624b06a9..6a8c0623ef 100644
--- a/spec/runtime/setup_spec.rb
+++ b/spec/runtime/setup_spec.rb
@@ -1,6 +1,44 @@
require File.expand_path('../../spec_helper', __FILE__)
describe "Bundler.setup" do
+ 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
+
+ run <<-R
+ begin
+ gem "activesupport"
+ puts "FAIL"
+ rescue LoadError
+ puts "WIN"
+ end
+ R
+
+ out.should == "WIN"
+ 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
+
+ run <<-R
+ begin
+ gem "rack", "1.0.0"
+ puts "FAIL"
+ rescue LoadError
+ puts "WIN"
+ end
+ R
+
+ out.should == "WIN"
+ end
+ end
+
describe "with paths" do
it "activates the gems in the path source" do
pending