Permalink
Browse files

Added simple enable/disable/optional settings for rubygems.

	Refactored a bunch of specs to make them full stack.
  • Loading branch information...
1 parent c04e9ff commit 7f7a7c2343350f1aaf559629fe6378d6d95f54be Carl Lerche committed Jul 23, 2009
View
@@ -14,18 +14,21 @@ def run
parser.parse!(@args)
manifest_file = Bundler::ManifestFile.load(@manifest)
- if ARGV.empty?
+ if @args.empty?
manifest_file.install
else
manifest_file.setup_environment
- exec(*ARGV)
+ exec(*@args)
end
rescue DefaultManifestNotFound => e
Bundler.logger.error "Could not find a Gemfile to use"
exit 2
rescue InvalidEnvironmentName => e
Bundler.logger.error "Gemfile error: #{e.message}"
exit
+ rescue VersionConflict => e
+ Bundler.logger.error e.message
+ exit
end
def parser
@@ -36,5 +36,10 @@ def to_gem_dependency
@gem_dep ||= Gem::Dependency.new(name, version)
end
+ def ==(o)
+ [name, version, require_as, only, except] ==
+ [o.name, o.version, o.require_as, o.only, o.except]
+ end
+
end
end
View
@@ -6,9 +6,13 @@ class VersionConflict < StandardError; end
class Manifest
attr_reader :sources, :dependencies, :path
- def initialize(sources, dependencies, bindir, gem_path)
+ def initialize(sources, dependencies, bindir, gem_path, rubygems)
sources.map! {|s| s.is_a?(URI) ? s : URI.parse(s) }
- @sources, @dependencies, @bindir, @gem_path = sources, dependencies, Pathname.new(bindir.to_s), Pathname.new(gem_path.to_s)
+ @sources = sources
+ @dependencies = dependencies
+ @bindir = bindir
+ @gem_path = gem_path
+ @rubygems = rubygems
end
def install
@@ -3,16 +3,17 @@ class DefaultManifestNotFound < StandardError; end
class ManifestFile
attr_reader :sources, :dependencies
- attr_accessor :gem_path, :bindir
+ attr_accessor :gem_path, :bindir, :rubygems
def self.load(filename = nil)
new(filename).load
end
def initialize(filename)
- @filename = filename
+ @filename = filename
@sources = %w(http://gems.rubyforge.org)
@dependencies = []
+ @rubygems = :optional
end
def load
@@ -34,7 +35,7 @@ def setup_environment
def load_manifest
ManifestBuilder.load(self, filename)
- Manifest.new(sources, dependencies, bindir, gem_path)
+ Manifest.new(sources, dependencies, bindir, gem_path, rubygems)
end
def gem_path
View
@@ -32,6 +32,14 @@ def bin_path(path)
@manifest_file.root.join(path) : path).expand_path
end
+ def disable_rubygems
+ @manifest_file.rubygems = :disable
+ end
+
+ def require_rubygems
+ @manifest_file.rubygems = :require
+ end
+
def source(source)
@manifest_file.sources << source
end
@@ -6,7 +6,14 @@ def self.rubygems_required
end
end
+<% if @rubygems == :optional %>
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))
+<% end %>
<% load_paths.each do |load_path| %>
$LOAD_PATH.unshift "<%= load_path %>"
+<% end %>
+<% if @rubygems == :require %>
+require "rubygems"
+<% elsif @rubygems == :disable %>
+$" << "rubygems.rb"
<% end %>
View
@@ -3,18 +3,15 @@
describe "Bundler::CLI" do
describe "it working" do
before(:all) do
- FileUtils.rm_rf(tmp_dir)
- FileUtils.mkdir_p(tmp_dir)
-
- File.open(tmp_file("Gemfile"), 'w') do |file|
- file.puts <<-DSL
- sources.clear
- source "file://#{gem_repo1}"
- gem "rake"
- gem "extlib"
- gem "rack", :only => :web
- DSL
- end
+ reset!
+
+ build_manifest <<-Gemfile
+ sources.clear
+ source "file://#{gem_repo1}"
+ gem "rake"
+ gem "extlib"
+ gem "rack", :only => :web
+ Gemfile
lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
bin = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'gem_bundler'))
@@ -24,14 +21,6 @@
end
end
- before(:each) do
- @original_pwd = Dir.pwd
- end
-
- after(:each) do
- Dir.chdir(@original_pwd)
- end
-
it "caches and installs rake" do
gems = %w(rake-0.8.7 extlib-0.9.12 rack-0.9.1)
tmp_file("vendor", "gems").should have_cached_gems(*gems)
@@ -73,4 +62,60 @@
end
end
end
+
+ describe "it working without rubygems" do
+ before(:all) do
+ reset!
+
+ build_manifest <<-Gemfile
+ sources.clear
+ source "file://#{gem_repo1}"
+ gem "rake"
+ gem "extlib"
+ gem "rack", :only => :web
+
+ disable_rubygems
+ Gemfile
+
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+ bin = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'gem_bundler'))
+
+ Dir.chdir(tmp_dir) do
+ @output = `#{Gem.ruby} -I #{lib} #{bin}`
+ end
+ end
+
+ it "does not load rubygems when required" do
+ out = `#{tmp_file('bin', 'rake')} -e 'require "rubygems" ; puts Gem rescue puts "No rubygems"'`
+ out.should =~ /No rubygems/
+ end
+ end
+
+ describe "it working with requiring rubygems automatically" do
+ before(:all) do
+ reset!
+
+ build_manifest <<-Gemfile
+ sources.clear
+ source "file://#{gem_repo1}"
+ gem "rake"
+ gem "extlib"
+ gem "rack", :only => :web
+
+ require_rubygems
+ Gemfile
+
+ lib = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+ bin = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'gem_bundler'))
+
+ Dir.chdir(tmp_dir) do
+ @output = `#{Gem.ruby} -I #{lib} #{bin}`
+ end
+ end
+
+ it "does already has rubygems required" do
+ out = `#{tmp_file('bin', 'rake')} -e 'puts Gem'`
+ out.should =~ /Gem/
+ end
+ end
end
View
@@ -3,15 +3,7 @@
describe "Bundling DSL" do
before(:all) do
- FileUtils.rm_rf(tmp_dir)
- FileUtils.mkdir_p(tmp_dir)
- end
-
- def build_manifest(str = "")
- File.open(tmp_file("Gemfile"), "w") do |f|
- f.puts str
- end
- Bundler::ManifestFile.load(tmp_file("Gemfile"))
+ reset!
end
it "allows specifying the path to bundle gems to" do
@@ -2,52 +2,38 @@
describe "Bundler::Manifest" do
before(:each) do
- @original_pwd = Dir.pwd
- FileUtils.rm_rf(tmp_dir)
- FileUtils.mkdir_p(tmp_dir)
- end
-
- after(:each) do
- Dir.chdir(@original_pwd)
- end
-
- def manifest(*args)
- path = args.unshift if args.first.is_a?(Pathname)
- str = args.unshift || ""
- File.open(path || tmp_file("Gemfile"), 'w') do |f|
- f.puts str
- end
+ reset!
end
it "finds the default manifest file" do
- manifest
+ build_manifest_file
Dir.chdir(tmp_dir)
Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile")
end
it "finds the default manifest file when it's in a parent directory" do
- manifest
+ build_manifest_file
FileUtils.mkdir_p(tmp_file("wot"))
Dir.chdir(tmp_file("wot"))
Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile")
end
it "sets the default bundle path to vendor/gems" do
- manifest
+ build_manifest_file
Dir.chdir(tmp_dir)
Bundler::ManifestFile.load.gem_path.should == tmp_file("vendor", "gems")
end
it "allows setting the bundle path in the manifest file" do
- manifest <<-Gemfile
+ build_manifest_file <<-Gemfile
bundle_path "#{tmp_file('gems')}"
Gemfile
Dir.chdir(tmp_dir)
Bundler::ManifestFile.load.gem_path.should == tmp_file("gems")
end
it "assumes the bundle_path is relative to the manifest file no matter what the current working dir is" do
- manifest <<-Gemfile
+ build_manifest_file <<-Gemfile
bundle_path File.join('..', 'cheezeburgerz')
Gemfile
FileUtils.mkdir_p(tmp_file('w0t'))
@@ -56,29 +42,29 @@ def manifest(*args)
end
it "sets the default bundle path relative to the Gemfile" do
- manifest
+ build_manifest_file
FileUtils.mkdir_p(tmp_file("wot"))
Dir.chdir(tmp_file("wot"))
Bundler::ManifestFile.load.gem_path.should == tmp_file("vendor", "gems")
end
it "sets the default bindir relative to the Gemfile" do
- manifest
+ build_manifest_file
FileUtils.mkdir_p(tmp_file("wot"))
Dir.chdir(tmp_file("wot"))
Bundler::ManifestFile.load.bindir.should == tmp_file("bin")
end
it "allows setting the bindir in the manifest file" do
- manifest <<-Gemfile
+ build_manifest_file <<-Gemfile
bin_path "#{tmp_file('binz')}"
Gemfile
Dir.chdir(tmp_dir)
Bundler::ManifestFile.load.bindir.should == tmp_file('binz')
end
it "assumes the bindir is relative to the manifest file no matter what the current working dir is" do
- manifest <<-Gemfile
+ build_manifest_file <<-Gemfile
bin_path File.join('..', 'cheezeburgerz')
Gemfile
FileUtils.mkdir_p(tmp_file('w0t'))
Oops, something went wrong.

0 comments on commit 7f7a7c2

Please sign in to comment.