diff --git a/lib/bundler/repository.rb b/lib/bundler/repository.rb index 38c7fe648fd..50a6a8d9e0c 100644 --- a/lib/bundler/repository.rb +++ b/lib/bundler/repository.rb @@ -62,7 +62,7 @@ def cleanup(bundle) repo.cleanup(bundle) end end - + def each_repo @repos.each do |k, repo| yield repo diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4a00e51bf1d..b21ef24e5df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,129 +4,16 @@ require "bundler" require "spec" -require "matchers" -require "builders" require "rbconfig" - -class Pathname - def mkdir_p - FileUtils.mkdir_p(self) - end - - def touch_p - dirname.mkdir_p - touch - end - - def touch - FileUtils.touch(self) - end -end - -module Spec - module Helpers - def this_file - Pathname.new(File.expand_path(File.dirname(__FILE__))) - end - - def tmp_dir - 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) - tmp_dir.join(*path) - end - - def cached(gem_name) - File.join(tmp_dir, 'cache', "#{gem_name}.gem") - end - - def fixture_dir - this_file.join("fixtures") - end - - def gem_repo1 - fixture_dir.join("repository1").expand_path - end - - def gem_repo2 - fixture_dir.join("repository2").expand_path - end - - def gem_repo3 - fixture_dir.join("repository3").expand_path - end - - def fixture(gem_name) - fixture_dir.join("repository1", "gems", "#{gem_name}.gem") - end - - def copy(gem_name) - FileUtils.cp(fixture(gem_name), File.join(tmp_dir, 'cache')) - end - - def run_in_context(*args) - cmd = args.pop.gsub(/(?=")/, "\\") - env = args.pop || tmp_file("vendor", "gems", "environment") - lib = File.join(File.dirname(__FILE__), '..', 'lib') - %x{#{Gem.ruby} -I#{lib} -r #{env} -e "#{cmd}"}.strip - end - - def gem_command(command, args = "") - if command == :exec - args = args.gsub(/(?=")/, "\\") - args = %["#{args}"] - end - lib = File.join(File.dirname(__FILE__), '..', 'lib') - %x{#{Gem.ruby} -I#{lib} -rubygems -S gem #{command} #{args}}.strip - end - - def build_manifest_file(*args) - path = tmp_file("Gemfile") - path = args.shift if args.first.is_a?(Pathname) - str = args.shift || "" - FileUtils.mkdir_p(path.dirname) - File.open(path, 'w') do |f| - f.puts str - end - end - - def build_manifest(*args) - path = tmp_file("Gemfile") - path = args.shift if args.first.is_a?(Pathname) - str = args.shift || "" - FileUtils.mkdir_p(path.dirname) - Dir.chdir(path.dirname) do - build_manifest_file(path, str) - Bundler::Environment.load(path) - end - end - - def install_manifest(*args) - m = build_manifest(*args) - m.install - m - end - - def reset! - tmp_dir.rmtree if tmp_dir.exist? - tmp_dir.mkdir - end - end +Dir[File.join(File.dirname(__FILE__), 'support', '*.rb')].each do |file| + require file end Spec::Runner.configure do |config| config.include Spec::Builders config.include Spec::Matchers config.include Spec::Helpers + config.include Spec::PathUtils original_wd = Dir.pwd diff --git a/spec/builders.rb b/spec/support/builders.rb similarity index 100% rename from spec/builders.rb rename to spec/support/builders.rb diff --git a/spec/support/core_ext.rb b/spec/support/core_ext.rb new file mode 100644 index 00000000000..59248cd7d66 --- /dev/null +++ b/spec/support/core_ext.rb @@ -0,0 +1,14 @@ +class Pathname + def mkdir_p + FileUtils.mkdir_p(self) + end + + def touch_p + dirname.mkdir_p + touch + end + + def touch + FileUtils.touch(self) + end +end \ No newline at end of file diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb new file mode 100644 index 00000000000..504718d012e --- /dev/null +++ b/spec/support/helpers.rb @@ -0,0 +1,51 @@ +module Spec + module Helpers + def run_in_context(*args) + cmd = args.pop.gsub(/(?=")/, "\\") + env = args.pop || tmp_file("vendor", "gems", "environment") + lib = File.join(File.dirname(__FILE__), '..', '..', 'lib') + %x{#{Gem.ruby} -I#{lib} -r #{env} -e "#{cmd}"}.strip + end + + def gem_command(command, args = "") + if command == :exec + args = args.gsub(/(?=")/, "\\") + args = %["#{args}"] + end + lib = File.join(File.dirname(__FILE__), '..', '..', 'lib') + %x{#{Gem.ruby} -I#{lib} -rubygems -S gem #{command} #{args}}.strip + end + + def build_manifest_file(*args) + path = tmp_file("Gemfile") + path = args.shift if args.first.is_a?(Pathname) + str = args.shift || "" + FileUtils.mkdir_p(path.dirname) + File.open(path, 'w') do |f| + f.puts str + end + end + + def build_manifest(*args) + path = tmp_file("Gemfile") + path = args.shift if args.first.is_a?(Pathname) + str = args.shift || "" + FileUtils.mkdir_p(path.dirname) + Dir.chdir(path.dirname) do + build_manifest_file(path, str) + Bundler::Environment.load(path) + end + end + + def install_manifest(*args) + m = build_manifest(*args) + m.install + m + end + + def reset! + tmp_dir.rmtree if tmp_dir.exist? + tmp_dir.mkdir + end + end +end \ No newline at end of file diff --git a/spec/matchers.rb b/spec/support/matchers.rb similarity index 100% rename from spec/matchers.rb rename to spec/support/matchers.rb diff --git a/spec/support/path_utils.rb b/spec/support/path_utils.rb new file mode 100644 index 00000000000..ccd890b7328 --- /dev/null +++ b/spec/support/path_utils.rb @@ -0,0 +1,51 @@ +module Spec + module PathUtils + def this_file + Pathname.new(__FILE__).dirname.join('..').expand_path + end + + def tmp_dir + 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) + tmp_dir.join(*path) + end + + def cached(gem_name) + File.join(tmp_dir, 'cache', "#{gem_name}.gem") + end + + def fixture_dir + this_file.join("fixtures") + end + + def gem_repo1 + fixture_dir.join("repository1").expand_path + end + + def gem_repo2 + fixture_dir.join("repository2").expand_path + end + + def gem_repo3 + fixture_dir.join("repository3").expand_path + end + + def fixture(gem_name) + fixture_dir.join("repository1", "gems", "#{gem_name}.gem") + end + + def copy(gem_name) + FileUtils.cp(fixture(gem_name), File.join(tmp_dir, 'cache')) + end + end +end \ No newline at end of file