Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Cleanup the spec directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed Aug 28, 2009
1 parent 7622e35 commit 75608df
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 117 deletions.
2 changes: 1 addition & 1 deletion lib/bundler/repository.rb
Expand Up @@ -62,7 +62,7 @@ def cleanup(bundle)
repo.cleanup(bundle)
end
end

def each_repo
@repos.each do |k, repo|
yield repo
Expand Down
119 changes: 3 additions & 116 deletions spec/spec_helper.rb
Expand Up @@ -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

Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions 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
51 changes: 51 additions & 0 deletions 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
File renamed without changes.
51 changes: 51 additions & 0 deletions 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

0 comments on commit 75608df

Please sign in to comment.