diff options
author | Andre Arko <andre@arko.net> | 2010-04-18 09:41:53 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2010-04-18 09:42:45 -0700 |
commit | 3e796f87bf7e20a0041850061071056a7e948e4b (patch) | |
tree | 0ffc93597d3314f0cc1705a5d1597531207c41b5 | |
parent | 41c9dc681335f70aa0bc4d2d02621c85801e1155 (diff) | |
download | bundler-3e796f87bf7e20a0041850061071056a7e948e4b.tar.gz |
Check for env.rb via ENV_LOADED instead of respond_to?(:require)
The rubygem 'polyglot', which is depended on by Cucumber via Treetop,
redefines the Kernel#require method, making it public instead of
private. This is pretty horrible. Libraries should not break the
behaviour of the stdlib. :(
This commit implements a workaround for that particular issue, with
a test that does the same thing polyglot does.
Closes #287
-rw-r--r-- | lib/bundler.rb | 4 | ||||
-rw-r--r-- | lib/bundler/templates/environment.erb | 1 | ||||
-rw-r--r-- | spec/runtime/environment_rb_spec.rb | 22 | ||||
-rw-r--r-- | spec/support/builders.rb | 4 |
4 files changed, 26 insertions, 5 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 6477775139..d32635ab93 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -87,12 +87,12 @@ module Bundler exit! end end - alias setup gem_setup unless Bundler.respond_to?(:setup) + alias setup gem_setup unless defined?(Bundler::ENV_LOADED) def gem_require(*groups) setup(*groups).require(*groups) end - alias require gem_require unless Bundler.respond_to?(:require) + alias require gem_require unless defined?(Bundler::ENV_LOADED) def load @load ||= begin diff --git a/lib/bundler/templates/environment.erb b/lib/bundler/templates/environment.erb index bca1c247ca..a905af5900 100644 --- a/lib/bundler/templates/environment.erb +++ b/lib/bundler/templates/environment.erb @@ -6,6 +6,7 @@ require 'yaml' <%= shared_helpers %> module Bundler + ENV_LOADED = true LOCKED_BY = '<%= Bundler::VERSION %>' FINGERPRINT = <%= gemfile_fingerprint.inspect %> HOME = '<%= Bundler.home %>' diff --git a/spec/runtime/environment_rb_spec.rb b/spec/runtime/environment_rb_spec.rb index 73215c1b2a..d2d7ae2f7a 100644 --- a/spec/runtime/environment_rb_spec.rb +++ b/spec/runtime/environment_rb_spec.rb @@ -218,7 +218,27 @@ describe "environment.rb file" do bundle :lock bundle %|exec ruby -e "require 'bundler'; Bundler.setup"| - err.should == "" + err.should be_empty + end + + it "handles polyglot making Kernel#require public :(" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + ruby <<-RUBY + require 'rubygems' + module Kernel + alias polyglot_original_require require + def require(*a, &b) + polyglot_original_require(*a, &b) + end + end + require 'bundler' + Bundler.require(:foo, :bar) + RUBY + err.should be_empty end end end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 2145cdc510..6118d89ad4 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -124,11 +124,11 @@ module Spec end build_gem "yard" do |s| - s.write "lib/yard.rb", <<-Y + s.write "lib/yard.rb", <<-RUBY Gem.source_index.find_name('').each do |gem| require gem.name end - Y + RUBY end # Test comlicated gem dependencies for install |