Permalink
Browse files

Removed .load from Bundler::Environment. the .load method will most l…

…ikely move again.
  • Loading branch information...
1 parent 4c2f79a commit ff2e0ce8b2e79847d1b3233b832b9d2c4f988cc1 Carlhuda committed Dec 11, 2009
View
@@ -32,7 +32,7 @@ def self.run(command, options = {})
def initialize(options)
@options = options
- @environment = Bundler::Environment.load(@options[:manifest])
+ @environment = Dsl.load_gemfile(@options[:manifest])
end
def bundle
View
@@ -1,11 +1,36 @@
module Bundler
class ManifestFileNotFound < StandardError; end
class InvalidKey < StandardError; end
+ class DefaultManifestNotFound < StandardError; end
class Dsl
- def self.evaluate(environment, file)
+ def self.load_gemfile(file)
+ gemfile = Pathname.new(file || default_gemfile).expand_path
+
+ unless gemfile.file?
+ raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
+ end
+
+ evaluate(gemfile)
+ end
+
+ def self.default_gemfile
+ current = Pathname.new(Dir.pwd)
+
+ until current.root?
+ filename = current.join("Gemfile")
+ return filename if filename.exist?
+ current = current.parent
+ end
+
+ raise DefaultManifestNotFound
+ end
+
+ def self.evaluate(file)
+ environment = Environment.new(file)
builder = new(environment)
builder.instance_eval(File.read(file.to_s), file.to_s, 1)
+ environment
end
def initialize(environment)
View
@@ -1,7 +1,6 @@
require "rubygems/source_index"
module Bundler
- class DefaultManifestNotFound < StandardError; end
class InvalidCacheArgument < StandardError; end
class SourceNotCached < StandardError; end
@@ -10,28 +9,6 @@ class Environment
attr_accessor :rubygems, :system_gems
attr_writer :gem_path, :bindir
- def self.load(file = nil)
- gemfile = Pathname.new(file || default_manifest_file).expand_path
-
- unless gemfile.file?
- raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
- end
-
- new(gemfile)
- end
-
- def self.default_manifest_file
- current = Pathname.new(Dir.pwd)
-
- until current.root?
- filename = current.join("Gemfile")
- return filename if filename.exist?
- current = current.parent
- end
-
- raise DefaultManifestNotFound
- end
-
def initialize(filename)
@filename = filename
@default_sources = default_sources
@@ -40,9 +17,6 @@ def initialize(filename)
@dependencies = []
@rubygems = true
@system_gems = true
-
- # Evaluate the Gemfile
- Dsl.evaluate(self, filename)
end
def install(options = {})
@@ -1,40 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-# More should probably loaded in here
-describe "Bundler::Environment" do
- it "can require the environment without being in context of it" do
- build_manifest <<-Gemfile
- clear_sources
- gem "rake"
- Gemfile
- Dir.chdir(bundled_app) do
- out = ruby <<-RUBY
- require 'bundler'
- Bundler::Environment.load.require_env
- puts defined?(Rake)
- RUBY
- out.should == "constant"
- end
- end
-
- it "only requires gems specific to the requested environment" do
- build_manifest <<-Gemfile
- clear_sources
- gem "rake", :only => "awesome"
- Gemfile
- Dir.chdir(bundled_app) do
- out = ruby <<-RUBY
- require 'bundler'
- Bundler::Environment.load.require_env
- puts defined?(Rake).inspect
- RUBY
- out.should == "nil"
- out = ruby <<-RUBY
- require 'bundler'
- Bundler::Environment.load.require_env(:awesome)
- puts defined?(Rake)
- RUBY
- out.should == "constant"
- end
- end
-end
@@ -2,118 +2,97 @@
describe "Bundler::Environment" do
- it "finds the default manifest file" do
- build_manifest_file
- Dir.chdir(bundled_app)
- Bundler::Environment.load.filename.should == bundled_app("Gemfile")
+ before :each do
+ simple_manifest
+ end
+
+ def simple_manifest(extra = nil)
+ build_manifest_file <<-Gemfile
+ clear_sources
+ source "file://#{gem_repo1}"
+ gem "rack"
+ #{extra}
+ Gemfile
+ end
+
+ def goto(where)
+ if where == :app
+ where = bundled_app
+ else
+ where = "#{bundled_app}/#{where}"
+ end
+
+ FileUtils.mkdir_p(where)
+ Dir.chdir(where)
+ end
+
+ def bundle
+ gem_command :bundle
+ end
+
+ def works
+ run_in_context("Bundler.require_env ; puts RACK").should == "1.0.0"
end
it "finds the default manifest file when it's in a parent directory" do
- build_manifest_file
- FileUtils.mkdir_p(bundled_app("wot"))
- Dir.chdir(bundled_app("wot"))
- Bundler::Environment.load.filename.should == bundled_app("Gemfile")
+ goto "wot"
+ bundle
+ works
end
it "sets the default bundle path to vendor/gems" do
- build_manifest_file
- Dir.chdir(bundled_app)
- Bundler::Environment.load.gem_path.should == bundled_app("vendor", "gems")
+ bundled_app("vendor/gems").should_not exist
+ goto :app
+ bundle
+ bundled_app("vendor/gems").should exist
end
it "allows setting the bundle path in the manifest file" do
- build_manifest_file <<-Gemfile
- bundle_path "#{bundled_app('gems')}"
- Gemfile
- Dir.chdir(bundled_app)
- Bundler::Environment.load.gem_path.should == bundled_app("gems")
+ simple_manifest %[bundle_path "#{bundled_app('gems')}"]
+ goto :app
+ bundle
+ bundled_app('gems').should exist
end
it "assumes the bundle_path is relative to the manifest file no matter what the current working dir is" do
- build_manifest_file <<-Gemfile
- bundle_path File.join('..', 'cheezeburgerz')
- Gemfile
- FileUtils.mkdir_p(bundled_app('w0t'))
- Dir.chdir(bundled_app('w0t'))
- Bundler::Environment.load.gem_path.should == tmp_path('cheezeburgerz')
- end
-
- it "sets the default bundle path relative to the Gemfile" do
- build_manifest_file
- FileUtils.mkdir_p(bundled_app("wot"))
- Dir.chdir(bundled_app("wot"))
- Bundler::Environment.load.gem_path.should == bundled_app("vendor", "gems")
+ simple_manifest %[bundle_path File.join('..', 'cheezeburgerz')]
+ goto 'w0t'
+ bundle
+ tmp_path('cheezeburgerz').should exist
end
it "sets the default bindir relative to the Gemfile" do
- build_manifest_file
- FileUtils.mkdir_p(bundled_app("wot"))
- Dir.chdir(bundled_app("wot"))
- Bundler::Environment.load.bindir.should == bundled_app("bin")
+ goto 'wot'
+ bundle
+ bundled_app("bin/rackup").should exist
end
it "allows setting the bindir in the manifest file" do
- build_manifest_file <<-Gemfile
- bin_path "#{bundled_app('binz')}"
- Gemfile
- Dir.chdir(bundled_app)
- Bundler::Environment.load.bindir.should == bundled_app('binz')
+ simple_manifest %[bin_path "#{bundled_app('binz')}"]
+ goto :app
+ bundle
+ bundled_app('binz/rackup').should exist
end
it "assumes the bindir is relative to the manifest file no matter what the current working dir is" do
- build_manifest_file <<-Gemfile
- bin_path File.join('..', 'cheezeburgerz')
- Gemfile
- FileUtils.mkdir_p(bundled_app('w0t'))
- Dir.chdir(bundled_app('w0t'))
- Bundler::Environment.load.bindir.should == tmp_path('cheezeburgerz')
+ simple_manifest %[bin_path File.join('..', 'cheezeburgerz')]
+ goto 'w0t'
+ bundle
+ tmp_path('cheezeburgerz/rackup').should exist
end
it "overwrites existing bin files" do
- bundled_app('bin').mkdir_p
- File.open("#{bundled_app}/bin/rackup", 'w') do |f|
- f.print "omg"
- end
-
- install_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo1}"
- gem "rack"
- Gemfile
-
- File.read("#{bundled_app}/bin/rackup").should_not == "omg"
+ bundled_app("bin/rackup").touch_p
+ goto :app
+ bundle
+ `#{bundled_app}/bin/rackup`.should == "1.0.0\n"
end
it "recreates the bin files if they are missing" do
- install_manifest <<-Gemfile
- clear_sources
- source "file://#{gem_repo1}"
- gem "rack"
- Gemfile
-
+ goto :app
+ bundle
bundled_app('bin/rackup').delete
- Dir.chdir(bundled_app) { gem_command :bundle }
+ bundle
bundled_app('bin/rackup').should exist
end
-
- it "ensures the source sources contains no duplicate" do
- build_manifest_file <<-Gemfile
- source "http://gems.rubyforge.org"
- source "http://gems.github.org"
- source "http://gems.github.org"
- Gemfile
- FileUtils.mkdir_p(bundled_app("baz"))
- Dir.chdir(bundled_app("baz"))
- Bundler::Environment.load.sources.should have(3).items
- end
-
- it "inserts new sources at the end if the default has been removed" do
- m = build_manifest <<-Gemfile
- clear_sources
- source "http://gems.rubyforge.org"
- source "http://gems.github.com"
- Gemfile
- m.sources.map{|s| s.uri.to_s}.should ==
- %w(http://gems.rubyforge.org http://gems.github.com)
- end
end
View
@@ -38,7 +38,7 @@ def build_manifest(*args)
FileUtils.mkdir_p(path.dirname)
Dir.chdir(path.dirname) do
build_manifest_file(path, str)
- Bundler::Environment.load(path)
+ Bundler::Dsl.load_gemfile(path)
end
end

0 comments on commit ff2e0ce

Please sign in to comment.