diff options
author | Tim Carey-Smith <tim@spork.in> | 2009-07-23 17:00:06 +1200 |
---|---|---|
committer | Tim Carey-Smith <tim@spork.in> | 2009-07-23 17:00:06 +1200 |
commit | a6314f196135b20dd0fda8d99d26e141a81cd472 (patch) | |
tree | 872bd23babc8d63d48fd282e06a3793429c43402 | |
parent | 7f1662efb855da76d19c5545e203a493d47aa79a (diff) | |
download | bundler-a6314f196135b20dd0fda8d99d26e141a81cd472.tar.gz |
Use the ManifestFile as the primary point of entry into the Bundler
-rwxr-xr-x | bin/gem_bundler | 33 | ||||
-rw-r--r-- | lib/bundler.rb | 8 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 63 | ||||
-rw-r--r-- | lib/bundler/dependency.rb | 7 | ||||
-rw-r--r-- | lib/bundler/gem_ext.rb | 3 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 2 | ||||
-rw-r--r-- | lib/bundler/manifest.rb | 33 | ||||
-rw-r--r-- | lib/bundler/manifest_file.rb | 70 | ||||
-rw-r--r-- | lib/bundler/runtime.rb | 42 | ||||
-rw-r--r-- | spec/bundler/cli_spec.rb | 49 | ||||
-rw-r--r-- | spec/bundler/dependency_spec.rb | 6 | ||||
-rw-r--r-- | spec/bundler/dsl_spec.rb | 21 | ||||
-rw-r--r-- | spec/bundler/manifest_file_spec.rb | 46 | ||||
-rw-r--r-- | spec/bundler/manifest_spec.rb | 64 | ||||
-rw-r--r-- | spec/spec_helper.rb | 12 |
15 files changed, 257 insertions, 202 deletions
diff --git a/bin/gem_bundler b/bin/gem_bundler index 09437f765b..f4e5777423 100755 --- a/bin/gem_bundler +++ b/bin/gem_bundler @@ -1,33 +1,4 @@ #!/usr/bin/env ruby -require "optparse" -require "bundler" - -options = {} - -parser = OptionParser.new do |op| - op.banner = "Usage: gem_bundler [OPTIONS] [PATH]" - - op.on("-m", "--manifest MANIFEST") do |manifest| - options[:manifest] = manifest - end - - op.on_tail("-h", "--help", "Show this message") do - puts op - exit - end -end -parser.parse! -options[:path] = ARGV.shift || Bundler::CLI.default_path - -options[:manifest] ||= Bundler::CLI.default_manifest - -unless File.exist?(options[:manifest]) - puts parser - puts %( - MANIFEST (#{options[:manifest]}) must exist - ) - exit -end - -Bundler.run(options)
\ No newline at end of file +require "bundler" +Bundler::CLI.run diff --git a/lib/bundler.rb b/lib/bundler.rb index a04ae3bbc7..e0775b08dd 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -11,6 +11,7 @@ require "bundler/installer" require "bundler/finder" require "bundler/gem_ext" require "bundler/resolver" +require "bundler/manifest_file" require "bundler/manifest" require "bundler/dependency" require "bundler/runtime" @@ -20,11 +21,6 @@ module Bundler VERSION = "0.5.0" class << self - def run(options = {}) - manifest = ManifestBuilder.load(options[:path], options[:manifest]) - manifest.install - end - attr_writer :logger def logger @@ -35,4 +31,4 @@ module Bundler end end end -end
\ No newline at end of file +end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index b7b622b2dd..d79feb3cdb 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -1,39 +1,46 @@ -module Bundler - module CLI - - module_function +require "optparse" - def default_manifest - return unless root? - root.join("Gemfile") +module Bundler + class CLI + def self.run(args = ARGV) + new(args).run end - def default_path - return unless root? - root.join("vendor", "gems") + def initialize(args) + @args = args end - def default_bindir - return unless root? - root.join("bin") + def run + parser.parse!(@args) + + manifest_file = Bundler::ManifestFile.load(@manifest) + if ARGV.empty? + manifest_file.install + else + manifest_file.setup_environment + exec(*ARGV) + 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 end - def root - return @root if @root - - current = Pathname.new(Dir.pwd) + def parser + @parser ||= OptionParser.new do |op| + op.banner = "Usage: gem_bundler [OPTIONS] [PATH]" - begin - @root = current if current.join("Gemfile").exist? - current = current.parent - end until current.root? + op.on("-m", "--manifest MANIFEST") do |manifest| + @manifest = manifest + end - @root ||= :none + op.on_tail("-h", "--help", "Show this message") do + puts op + exit + end + end end - - def root? - root != :none - end - end -end
\ No newline at end of file + end diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index bd40b5fb35..1346d3d9c7 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -1,6 +1,7 @@ module Bundler - class Dependency + class InvalidEnvironmentName < StandardError; end + class Dependency attr_reader :name, :version, :require_as, :only, :except def initialize(name, options = {}) @@ -15,7 +16,7 @@ module Bundler @except = Array(options["except"]).map {|e| e.to_s } if options["except"] if (@only && @only.include?("rubygems")) || (@except && @except.include?("rubygems")) - raise ArgumentError, "'rubygems' is not a valid environment name" + raise InvalidEnvironmentName, "'rubygems' is not a valid environment name" end end @@ -36,4 +37,4 @@ module Bundler end end -end
\ No newline at end of file +end diff --git a/lib/bundler/gem_ext.rb b/lib/bundler/gem_ext.rb index c1a7e20d3d..8a38322326 100644 --- a/lib/bundler/gem_ext.rb +++ b/lib/bundler/gem_ext.rb @@ -1,8 +1,7 @@ module Gem class Installer def app_script_text(bin_file_name) - return unless Bundler::CLI.default_path - path = Pathname.new(Bundler::CLI.default_path).expand_path + path = @gem_home template = File.read(File.join(File.dirname(__FILE__), "templates", "app_script.rb")) erb = ERB.new(template) erb.result(binding) diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 99d5df93c5..4124eb38e3 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -37,4 +37,4 @@ module Bundler end end end -end
\ No newline at end of file +end diff --git a/lib/bundler/manifest.rb b/lib/bundler/manifest.rb index 7af44c5c00..f0855b9f08 100644 --- a/lib/bundler/manifest.rb +++ b/lib/bundler/manifest.rb @@ -6,23 +6,30 @@ module Bundler class Manifest attr_reader :sources, :dependencies, :path - def initialize(sources, dependencies, path) + def initialize(sources, dependencies, bindir, gem_path) sources.map! {|s| s.is_a?(URI) ? s : URI.parse(s) } - @sources, @dependencies, @path = sources, dependencies, Pathname.new(path) + @sources, @dependencies, @bindir, @gem_path = sources, dependencies, Pathname.new(bindir.to_s), Pathname.new(gem_path.to_s) end - def install(options = {}) + def install fetch - installer = Installer.new(@path) - installer.install(:bin_dir => options[:bin_dir] || CLI.default_bindir) + installer = Installer.new(@gem_path) + installer.install(:bin_dir => @bindir) cleanup_removed_gems - create_load_paths_files(@path.join("environments")) - create_fake_rubygems(@path.join("environments")) + create_load_paths_files(@gem_path.join("environments")) + create_fake_rubygems(@gem_path.join("environments")) Bundler.logger.info "Done." end def activate(environment = "default") - require @path.join("environments", "#{environment}.rb") + require @gem_path.join("environments", "#{environment}.rb") + end + + def setup_environment + ENV["GEM_HOME"] = @gem_path + ENV["GEM_PATH"] = @gem_path + ENV["PATH"] = "#{@bindir}:#{ENV["PATH"]}" + ENV["RUBYOPT"] = "-r#{@gem_path}/environments/default #{ENV["RUBYOPT"]}" end def require_all @@ -35,7 +42,7 @@ module Bundler deps = dependencies deps = deps.select { |d| d.in?(environment) } if environment deps = deps.map { |d| d.to_gem_dependency } - index = Gem::SourceIndex.from_gems_in(@path.join("specifications")) + index = Gem::SourceIndex.from_gems_in(@gem_path.join("specifications")) Resolver.resolve(deps, index).all_specs end alias gems gems_for @@ -56,7 +63,7 @@ module Bundler raise VersionConflict, "No compatible versions could be found for:\n#{gems}" end - bundle.download(@path) + bundle.download(@gem_path) end def gem_dependencies @@ -66,7 +73,7 @@ module Bundler def all_gems_installed? downloaded_gems = {} - Dir[@path.join("cache", "*.gem")].each do |file| + Dir[@gem_path.join("cache", "*.gem")].each do |file| file =~ /\/([^\/]+)-([\d\.]+)\.gem$/ name, version = $1, $2 downloaded_gems[name] = Gem::Version.new(version) @@ -80,7 +87,7 @@ module Bundler def cleanup_removed_gems glob = gems.map { |g| g.full_name }.join(',') - base = @path.join("{cache,specifications,gems}") + base = @gem_path.join("{cache,specifications,gems}") (Dir[base.join("*")] - Dir[base.join("{#{glob}}{.gemspec,.gem,}")]).each do |file| Bundler.logger.info "Deleting #{File.basename(file)}" if File.basename(file) =~ /\.gem$/ @@ -133,4 +140,4 @@ module Bundler files end end -end
\ No newline at end of file +end diff --git a/lib/bundler/manifest_file.rb b/lib/bundler/manifest_file.rb new file mode 100644 index 0000000000..aa0222fee1 --- /dev/null +++ b/lib/bundler/manifest_file.rb @@ -0,0 +1,70 @@ +module Bundler + class DefaultManifestNotFound < StandardError; end + + class ManifestFile + attr_reader :sources, :dependencies, :gem_path, :bindir + + def self.load(filename = nil) + new(filename).load + end + + def initialize(filename) + @filename = filename + @sources = %w(http://gems.rubyforge.org) + @dependencies = [] + end + + def load + manifest + self + end + + def manifest + @manifest ||= load_manifest + end + + def install + manifest.install + end + + def setup_environment + manifest.setup_environment + end + + def load_manifest + builder = ManifestBuilder.load(self, filename) + Manifest.new(sources, + dependencies, + bindir, + gem_path) + end + + def gem_path + @gem_path ||= root.join("vendor", "gems") + end + + def bindir + @bindir ||= root.join("bin") + end + + def root + filename.parent + end + + def filename + @filename ||= find_manifest_file + end + + def find_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 + end +end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 9a152ff249..265eb2b69f 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -1,42 +1,38 @@ module Bundler - class ManifestBuilder - - attr_reader :sources + class ManifestFileNotFound < StandardError; end - def self.build(path, string) - builder = new(path) + class ManifestBuilder + def self.build(manifest_file, string) + builder = new(manifest_file) builder.instance_eval(string) - builder.to_manifest - rescue ArgumentError - Bundler.logger.error "Gemfile error: 'rubygems' cannot be used as an environment name" - exit + builder end - def self.load(path, file) - string = File.read(file) - build(path, string) + def self.load(manifest_file, filename) + unless File.exist?(filename) + raise ManifestFileNotFound, "#{filename.inspect} does not exist" + end + string = File.read(filename) + build(manifest_file, string) end - def initialize(path) - @path = path - @sources = %w(http://gems.rubyforge.org) - @dependencies = [] + def initialize(manifest_file) + @manifest_file = manifest_file end - def to_manifest - Manifest.new(@sources, @dependencies, @path) + def source(source) + @manifest_file.sources << source end - def source(source) - @sources << source + def sources + @manifest_file.sources end def gem(name, *args) options = args.last.is_a?(Hash) ? args.pop : {} version = args.last - @dependencies << Dependency.new(name, options.merge(:version => version)) + @manifest_file.dependencies << Dependency.new(name, options.merge(:version => version)) end - end -end
\ No newline at end of file +end diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index 6722ede4aa..08038a09a1 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -1,53 +1,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "Bundler::CLI" do - - describe "helper methods" do - before(:each) do - @original_pwd = Dir.pwd - FileUtils.rm_rf(tmp_dir) - FileUtils.mkdir_p(tmp_dir) - @cli = Bundler::CLI - end - - after(:each) do - Dir.chdir(@original_pwd) - end - - it "finds the default manifest file" do - Dir.chdir(tmp_dir) - FileUtils.touch(tmp_file("Gemfile")) - @cli.default_manifest.should == tmp_file("Gemfile") - end - - it "finds the default manifest file when it's in a parent directory" do - FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) - Dir.chdir(tmp_file("wot")) - @cli.default_manifest.should == tmp_file("Gemfile") - end - - it "sets the default bundle path to vendor/gems" do - Dir.chdir(tmp_dir) - FileUtils.touch(tmp_file("Gemfile")) - @cli.default_path.should == tmp_file("vendor", "gems") - end - - it "sets the default bundle path relative to the Gemfile" do - FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) - Dir.chdir(tmp_file("wot")) - @cli.default_path.should == tmp_file("vendor", "gems") - end - - it "sets the default bindir relative to the Gemfile" do - FileUtils.mkdir_p(tmp_file("wot")) - FileUtils.touch(tmp_file("Gemfile")) - Dir.chdir(tmp_file("wot")) - @cli.default_bindir.should == tmp_file("bin") - end - end - describe "it working" do before(:all) do FileUtils.rm_rf(tmp_dir) @@ -120,4 +73,4 @@ describe "Bundler::CLI" do end end end -end
\ No newline at end of file +end diff --git a/spec/bundler/dependency_spec.rb b/spec/bundler/dependency_spec.rb index 04347647a3..61a4b00883 100644 --- a/spec/bundler/dependency_spec.rb +++ b/spec/bundler/dependency_spec.rb @@ -40,9 +40,9 @@ describe "Bundler::Dependency" do it "disallows the :rubygems environment" do lambda { Bundler::Dependency.new("ruby-debug", :only => "rubygems") }. - should raise_error(ArgumentError) + should raise_error(Bundler::InvalidEnvironmentName) lambda { Bundler::Dependency.new("ruby-debug", :except => "rubygems") }. - should raise_error(ArgumentError) + should raise_error(Bundler::InvalidEnvironmentName) end it "tests whether a dependency is for a specific environment (with :only)" do @@ -84,4 +84,4 @@ describe "Bundler::Dependency" do b.should be_in("development") b.should be_in(:development) end -end
\ No newline at end of file +end diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb index 07c09d5308..91cd9d5278 100644 --- a/spec/bundler/dsl_spec.rb +++ b/spec/bundler/dsl_spec.rb @@ -8,11 +8,14 @@ describe "Bundling DSL" do end def build_manifest(str = "") - Bundler::ManifestBuilder.build(tmp_dir, str) + File.open(tmp_file("Gemfile"), "w") do |f| + f.puts str + end + Bundler::ManifestFile.load(tmp_file("Gemfile")) end it "allows specifying the path to bundle gems to" do - build_manifest.path.should == tmp_dir + build_manifest.gem_path.should == tmp_file("vendor", "gems") end it "allows specifying sources" do @@ -71,7 +74,7 @@ describe "Bundling DSL" do DSL end - manifest = Bundler::ManifestBuilder.load(tmp_dir, tmp_file("manifest.rb")) + manifest = Bundler::ManifestFile.load(tmp_file("manifest.rb")) manifest.dependencies.first.name.should == "rails" end @@ -116,13 +119,13 @@ describe "Bundling DSL" do manifest.install - tmp_dir.should have_cached_gems(*gems) - tmp_dir.should have_installed_gems(*gems) + tmp_gem_path.should have_cached_gems(*gems) + tmp_gem_path.should have_installed_gems(*gems) load_paths = {} gems.each { |g| load_paths[g] = %w(bin lib) } - tmp_file('environments', 'default.rb').should have_load_paths(tmp_dir, load_paths) + tmp_gem_path('environments', 'default.rb').should have_load_paths(tmp_gem_path, load_paths) end it "outputs a pretty error when an environment is named rubygems" do @@ -132,8 +135,6 @@ describe "Bundling DSL" do gem "extlib", :only => "rubygems" DSL - end.should raise_error(SystemExit) - - @log_output.should have_log_message("Gemfile error: 'rubygems' cannot be used as an environment name") + end.should raise_error(Bundler::InvalidEnvironmentName) end -end
\ No newline at end of file +end diff --git a/spec/bundler/manifest_file_spec.rb b/spec/bundler/manifest_file_spec.rb new file mode 100644 index 0000000000..5b18220e47 --- /dev/null +++ b/spec/bundler/manifest_file_spec.rb @@ -0,0 +1,46 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +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 + + it "finds the default manifest file" do + Dir.chdir(tmp_dir) + FileUtils.touch(tmp_file("Gemfile")) + Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile") + end + + it "finds the default manifest file when it's in a parent directory" do + FileUtils.mkdir_p(tmp_file("wot")) + FileUtils.touch(tmp_file("Gemfile")) + Dir.chdir(tmp_file("wot")) + Bundler::ManifestFile.load.filename.should == tmp_file("Gemfile") + end + + it "sets the default bundle path to vendor/gems" do + Dir.chdir(tmp_dir) + FileUtils.touch(tmp_file("Gemfile")) + Bundler::ManifestFile.load.gem_path.should == tmp_file("vendor", "gems") + end + + it "sets the default bundle path relative to the Gemfile" do + FileUtils.mkdir_p(tmp_file("wot")) + FileUtils.touch(tmp_file("Gemfile")) + 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 + FileUtils.mkdir_p(tmp_file("wot")) + FileUtils.touch(tmp_file("Gemfile")) + Dir.chdir(tmp_file("wot")) + Bundler::ManifestFile.load.bindir.should == tmp_file("bin") + end +end diff --git a/spec/bundler/manifest_spec.rb b/spec/bundler/manifest_spec.rb index 08e0d1fd8b..46d7446a2b 100644 --- a/spec/bundler/manifest_spec.rb +++ b/spec/bundler/manifest_spec.rb @@ -18,7 +18,7 @@ describe "Bundler::Manifest" do before(:each) do FileUtils.rm_rf(tmp_dir) FileUtils.mkdir_p(tmp_dir) - @manifest = Bundler::Manifest.new(@sources, @deps, tmp_dir) + @manifest = Bundler::Manifest.new(@sources, @deps, tmp_bindir, tmp_gem_path) @saved_load_path, @saved_loaded_features = $:.dup, $".dup end @@ -41,8 +41,8 @@ describe "Bundler::Manifest" do rake-0.8.7 actionpack-2.3.2 activeresource-2.3.2 rails-2.3.2) - tmp_dir.should have_cached_gems(*gems) - tmp_dir.should have_installed_gems(*gems) + tmp_gem_path.should have_cached_gems(*gems) + tmp_gem_path.should have_installed_gems(*gems) end it "skips fetching the source index if all gems are present" do @@ -64,7 +64,7 @@ describe "Bundler::Manifest" do deps << dep("rails", "2.3.2") deps << dep("rack", "1.0.0") - manifest = Bundler::Manifest.new(@sources,deps, tmp_dir) + manifest = Bundler::Manifest.new(@sources, deps, tmp_bindir, tmp_gem_path) manifest.install gems = %w(rack-1.0.0 actionmailer-2.3.2 @@ -72,37 +72,37 @@ describe "Bundler::Manifest" do rake-0.8.7 actionpack-2.3.2 activeresource-2.3.2 rails-2.3.2) - tmp_dir.should have_cached_gems(*gems) - tmp_dir.should have_installed_gems(*gems) + tmp_gem_path.should have_cached_gems(*gems) + tmp_gem_path.should have_installed_gems(*gems) end it "removes gems that are not needed anymore" do @manifest.install - tmp_dir.should have_cached_gem("rack-0.9.1") - tmp_dir.should have_installed_gem("rack-0.9.1") - tmp_file("bin", "rackup").should exist + tmp_gem_path.should have_cached_gem("rack-0.9.1") + tmp_gem_path.should have_installed_gem("rack-0.9.1") + tmp_bindir("rackup").should exist deps = @deps.dup deps.pop - manifest = Bundler::Manifest.new(@sources, deps, tmp_dir) + manifest = Bundler::Manifest.new(@sources, deps, tmp_bindir, tmp_gem_path) manifest.install - tmp_dir.should_not have_cached_gem("rack-0.9.1") - tmp_dir.should_not have_installed_gem("rack-0.9.1") - tmp_file("bin", "rackup").should_not exist + tmp_gem_path.should_not have_cached_gem("rack-0.9.1") + tmp_gem_path.should_not have_installed_gem("rack-0.9.1") + tmp_bindir("rackup").should_not exist @log_output.should have_log_message("Deleting rack-0.9.1.gem") end it "removes stray specfiles" do - spec = tmp_file("specifications", "omg.gemspec") - FileUtils.mkdir_p(tmp_file("specifications")) + spec = tmp_gem_path("specifications", "omg.gemspec") + FileUtils.mkdir_p(tmp_gem_path("specifications")) FileUtils.touch(spec) @manifest.install spec.should_not exist end it "removes any stray directories in gems that are not to be installed" do - dir = tmp_file("gems", "omg") + dir = tmp_gem_path("gems", "omg") FileUtils.mkdir_p(dir) @manifest.install dir.should_not exist @@ -123,17 +123,17 @@ describe "Bundler::Manifest" do end it "makes gems available via Manifest#activate" do - manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_dir) + manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_bindir, tmp_gem_path) manifest.install manifest.activate $:.any? do |p| - File.expand_path(p) == File.expand_path(tmp_file("gems", "very-simple-1.0", "lib")) + File.expand_path(p) == File.expand_path(tmp_gem_path("gems", "very-simple-1.0", "lib")) end.should be_true end it "makes gems available" do - manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_dir) + manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0")], tmp_bindir, tmp_gem_path) manifest.install manifest.activate @@ -141,7 +141,7 @@ describe "Bundler::Manifest" do $".any? do |f| File.expand_path(f) == - File.expand_path(tmp_file("gems", "very-simple-1.0", "lib", "very-simple.rb")) + File.expand_path(tmp_gem_path("gems", "very-simple-1.0", "lib", "very-simple.rb")) end end end @@ -152,7 +152,7 @@ describe "Bundler::Manifest" do FileUtils.mkdir_p(tmp_dir) @manifest = Bundler::Manifest.new(@sources, [dep("very-simple", "1.0.0", :only => "testing"), - dep("rack", "1.0.0")], tmp_dir) + dep("rack", "1.0.0")], tmp_bindir, tmp_gem_path) @manifest.install end @@ -170,53 +170,53 @@ describe "Bundler::Manifest" do end it "can create load path files for each environment" do - tmp_file('environments', 'testing.rb').should have_load_paths(tmp_dir, + tmp_gem_path('environments', 'testing.rb').should have_load_paths(tmp_gem_path, "very-simple-1.0" => %w(bin lib), "rack-1.0.0" => %w(bin lib) ) - tmp_file('environments', 'default.rb').should have_load_paths(tmp_dir, + tmp_gem_path('environments', 'default.rb').should have_load_paths(tmp_gem_path, "rack-1.0.0" => %w(bin lib) ) - File.exist?(tmp_file('environments', "production.rb")).should be_false + File.exist?(tmp_gem_path('environments', "production.rb")).should be_false end it "adds the environments path to the load paths" do - tmp_file('environments', 'testing.rb').should have_load_paths(tmp_dir, [ + tmp_gem_path('environments', 'testing.rb').should have_load_paths(tmp_gem_path, [ "environments" ]) end it "creates a rubygems.rb file in the environments directory" do - File.exist?(tmp_file('environments', 'rubygems.rb')).should be_true + File.exist?(tmp_gem_path('environments', 'rubygems.rb')).should be_true end it "requires the Rubygems library" do - env = tmp_file('environments', 'default.rb') + env = tmp_gem_path('environments', 'default.rb') out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem'`.strip out.should == 'Gem' end it "removes the environments path from the load paths after rubygems is required" do - env = tmp_file('environments', 'default.rb') + env = tmp_gem_path('environments', 'default.rb') out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts $:'` - out.should_not include(tmp_file('environments')) + out.should_not include(tmp_gem_path('environments')) end it "Gem.loaded_specs has the gems that are included" do - env = tmp_file('environments', 'default.rb') + env = tmp_gem_path('environments', 'default.rb') out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem.loaded_specs.map{|k,v|"\#{k} - \#{v.version}"}'` out = out.split("\n") out.should include("rack - 1.0.0") end it "Gem.loaded_specs has the gems that are included in the testing environment" do - env = tmp_file('environments', 'testing.rb') + env = tmp_gem_path('environments', 'testing.rb') out = `#{Gem.ruby} -r #{env} -r rubygems -e 'puts Gem.loaded_specs.map{|k,v|"\#{k} - \#{v.version}"}'` out = out.split("\n") out.should include("rack - 1.0.0") out.should include("very-simple - 1.0") end end -end
\ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ecc7b8c4a2..db53ad6b01 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,15 @@ module Spec end def tmp_dir - this_file.join("fixtures", "tmp") + this_file.join("..", "tmp") + end + + def tmp_gem_path(*path) + tmp_file("vendor", "gems").join(*path) + end + + def tmp_bindir(*path) + tmp_file("bin").join(*path) end def tmp_file(*path) @@ -60,4 +68,4 @@ Spec::Runner.configure do |config| @log_output.rewind @log_output.string.replace "" end -end
\ No newline at end of file +end |