Skip to content

Commit

Permalink
Check for env.rb via ENV_LOADED instead of respond_to?(:require)
Browse files Browse the repository at this point in the history
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 rubygems#287
  • Loading branch information
indirect committed Apr 18, 2010
1 parent 41c9dc6 commit 3e796f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def gem_setup(*groups)
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
Expand Down
1 change: 1 addition & 0 deletions lib/bundler/templates/environment.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require 'yaml'
<%= shared_helpers %>

module Bundler
ENV_LOADED = true
LOCKED_BY = '<%= Bundler::VERSION %>'
FINGERPRINT = <%= gemfile_fingerprint.inspect %>
HOME = '<%= Bundler.home %>'
Expand Down
22 changes: 21 additions & 1 deletion spec/runtime/environment_rb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,27 @@ def Bundler.require(path)
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
4 changes: 2 additions & 2 deletions spec/support/builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def build_repo1
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
Expand Down

0 comments on commit 3e796f8

Please sign in to comment.