summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/builders.rb76
-rw-r--r--spec/support/helpers.rb28
-rw-r--r--spec/support/path.rb12
-rw-r--r--spec/support/rubygems_version_manager.rb10
4 files changed, 59 insertions, 67 deletions
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index 021057cc3c..467a9f2ccd 100644
--- a/spec/support/builders.rb
+++ b/spec/support/builders.rb
@@ -394,7 +394,7 @@ module Spec
@_build_repo = File.basename(path)
yield
with_gem_path_as Path.base_system_gems do
- Dir.chdir(path) { gem_command! :generate_index }
+ gem_command! :generate_index, :dir => path
end
ensure
@_build_path = nil
@@ -551,6 +551,11 @@ module Spec
@files = {}
end
+ def capture(cmd, dir)
+ output, _status = Open3.capture2e(cmd, :chdir => dir)
+ output
+ end
+
def method_missing(*args, &blk)
@spec.send(*args, &blk)
end
@@ -660,14 +665,12 @@ module Spec
path = options[:path] || _default_path
source = options[:source] || "git@#{path}"
super(options.merge(:path => path, :source => source))
- Dir.chdir(path) do
- `git init`
- `git add *`
- `git config user.email "lol@wut.com"`
- `git config user.name "lolwut"`
- `git config commit.gpgsign false`
- `git commit -m "OMG INITIAL COMMIT"`
- end
+ capture("git init", path)
+ capture("git add *", path)
+ capture("git config user.email \"lol@wut.com\"", path)
+ capture("git config user.name \"lolwut\"", path)
+ capture("git config commit.gpgsign false", path)
+ capture("git commit -m \"OMG INITIAL COMMIT\"", path)
end
end
@@ -675,15 +678,14 @@ module Spec
def _build(options)
path = options[:path] || _default_path
super(options.merge(:path => path))
- Dir.chdir(path) do
- `git init --bare`
- end
+ capture("git init --bare", path)
end
end
class GitUpdater < LibBuilder
- def silently(str)
- `#{str} 2>#{Bundler::NULL}`
+ def silently(str, dir)
+ output, _error, _status = Open3.capture3(str, :chdir => dir)
+ output
end
def _build(options)
@@ -691,34 +693,32 @@ module Spec
update_gemspec = options[:gemspec] || false
source = options[:source] || "git@#{libpath}"
- Dir.chdir(libpath) do
- silently "git checkout master"
+ silently "git checkout master", libpath
- if branch = options[:branch]
- raise "You can't specify `master` as the branch" if branch == "master"
- escaped_branch = Shellwords.shellescape(branch)
+ if branch = options[:branch]
+ raise "You can't specify `master` as the branch" if branch == "master"
+ escaped_branch = Shellwords.shellescape(branch)
- if `git branch | grep #{escaped_branch}`.empty?
- silently("git branch #{escaped_branch}")
- end
-
- silently("git checkout #{escaped_branch}")
- elsif tag = options[:tag]
- `git tag #{Shellwords.shellescape(tag)}`
- elsif options[:remote]
- silently("git remote add origin #{options[:remote]}")
- elsif options[:push]
- silently("git push origin #{options[:push]}")
+ if capture("git branch | grep #{escaped_branch}", libpath).empty?
+ silently("git branch #{escaped_branch}", libpath)
end
- current_ref = `git rev-parse HEAD`.strip
- _default_files.keys.each do |path|
- _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'"
- end
- super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source))
- `git add *`
- `git commit -m "BUMP"`
+ silently("git checkout #{escaped_branch}", libpath)
+ elsif tag = options[:tag]
+ capture("git tag #{Shellwords.shellescape(tag)}", libpath)
+ elsif options[:remote]
+ silently("git remote add origin #{options[:remote]}", libpath)
+ elsif options[:push]
+ silently("git push origin #{options[:push]}", libpath)
+ end
+
+ current_ref = silently("git rev-parse HEAD", libpath).strip
+ _default_files.keys.each do |path|
+ _default_files[path] += "\n#{Builders.constantize(name)}_PREV_REF = '#{current_ref}'"
end
+ super(options.merge(:path => libpath, :gemspec => update_gemspec, :source => source))
+ capture("git add *", libpath)
+ capture("git commit -m \"BUMP\"", libpath)
end
end
@@ -739,7 +739,7 @@ module Spec
def git(cmd)
Bundler::SharedHelpers.with_clean_git_env do
- Dir.chdir(@path) { `git #{cmd}`.strip }
+ Open3.capture2e("git #{cmd}", :chdir => path)[0].strip
end
end
end
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index 4180a2f1ae..dde8daaf6f 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -114,6 +114,8 @@ module Spec
load_path << spec_dir
load_path_str = "-I#{load_path.join(File::PATH_SEPARATOR)}"
+ dir = options.delete(:dir) || bundled_app
+
args = options.map do |k, v|
case v
when nil
@@ -128,7 +130,7 @@ module Spec
end.join
cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
- sys_exec(cmd, { :env => env }, &block)
+ sys_exec(cmd, { :env => env, :dir => dir }, &block)
end
bang :bundle
@@ -170,17 +172,17 @@ module Spec
R
end
- def gembin(cmd)
+ def gembin(cmd, options = {})
old = ENV["RUBYOPT"]
ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}"
cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/")
- sys_exec(cmd.to_s)
+ sys_exec(cmd.to_s, options)
ensure
ENV["RUBYOPT"] = old
end
- def gem_command(command)
- sys_exec("#{Path.gem_bin} #{command}")
+ def gem_command(command, options = {})
+ sys_exec("#{Path.gem_bin} #{command}", options)
end
bang :gem_command
@@ -190,11 +192,12 @@ module Spec
def sys_exec(cmd, options = {})
env = options[:env] || {}
- command_execution = CommandExecution.new(cmd.to_s, Dir.pwd)
+ dir = options[:dir] || bundled_app
+ command_execution = CommandExecution.new(cmd.to_s, dir)
require "open3"
require "shellwords"
- Open3.popen3(env, *cmd.shellsplit) do |stdin, stdout, stderr, wait_thr|
+ Open3.popen3(env, *cmd.shellsplit, :chdir => dir) do |stdin, stdout, stderr, wait_thr|
yield stdin, stdout, wait_thr if block_given?
stdin.close
@@ -238,7 +241,7 @@ module Spec
contents = args.shift
if contents.nil?
- File.open("Gemfile", "r", &:read)
+ File.open(bundled_app_gemfile, "r", &:read)
else
create_file("Gemfile", contents, *args)
end
@@ -248,7 +251,7 @@ module Spec
contents = args.shift
if contents.nil?
- File.open("Gemfile.lock", "r", &:read)
+ File.open(bundled_app_lock, "r", &:read)
else
create_file("Gemfile.lock", contents, *args)
end
@@ -297,7 +300,7 @@ module Spec
def with_built_bundler
with_root_gemspec do |gemspec|
- in_repo_root { gem_command! "build #{gemspec}" }
+ gem_command! "build #{gemspec}", :dir => root
end
bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
@@ -357,7 +360,8 @@ module Spec
opts = gems.last.is_a?(Hash) ? gems.last : {}
path = opts.fetch(:path, system_gem_path)
if path == :bundle_path
- path = ruby!(<<-RUBY)
+ bundle_dir = opts.fetch(:bundle_dir, bundled_app)
+ path = ruby!(<<-RUBY, :dir => bundle_dir)
require "bundler"
begin
puts Bundler.bundle_path
@@ -494,7 +498,7 @@ module Spec
end
def revision_for(path)
- Dir.chdir(path) { `git rev-parse HEAD`.strip }
+ sys_exec("git rev-parse HEAD", :dir => path).strip
end
def with_read_only(pattern)
diff --git a/spec/support/path.rb b/spec/support/path.rb
index a645aa6ffd..25206c9832 100644
--- a/spec/support/path.rb
+++ b/spec/support/path.rb
@@ -48,13 +48,13 @@ module Spec
def lib_tracked_files
skip "not in git working directory" unless git_root_dir?
- @lib_tracked_files ||= ruby_core? ? `git ls-files -z -- lib/bundler lib/bundler.rb` : `git ls-files -z -- lib`
+ @lib_tracked_files ||= ruby_core? ? sys_exec("git ls-files -z -- lib/bundler lib/bundler.rb", :dir => root) : sys_exec("git ls-files -z -- lib", :dir => root)
end
def man_tracked_files
skip "not in git working directory" unless git_root_dir?
- @man_tracked_files ||= `git ls-files -z -- man`
+ @man_tracked_files ||= sys_exec("git ls-files -z -- man", :dir => root)
end
def tmp(*path)
@@ -194,14 +194,6 @@ module Spec
end
end
- def in_app_root
- Dir.chdir(bundled_app) { yield }
- end
-
- def in_app_root2
- Dir.chdir(bundled_app2) { yield }
- end
-
def in_repo_root
Dir.chdir(root) { yield }
end
diff --git a/spec/support/rubygems_version_manager.rb b/spec/support/rubygems_version_manager.rb
index 854bce890d..8eab7749f9 100644
--- a/spec/support/rubygems_version_manager.rb
+++ b/spec/support/rubygems_version_manager.rb
@@ -44,10 +44,8 @@ private
def switch_local_copy_if_needed
return unless local_copy_switch_needed?
- Dir.chdir(local_copy_path) do
- sys_exec!("git remote update")
- sys_exec!("git checkout #{target_tag} --quiet")
- end
+ sys_exec!("git remote update", :dir => local_copy_path)
+ sys_exec!("git checkout #{target_tag} --quiet", :dir => local_copy_path)
ENV["RGV"] = local_copy_path.to_s
end
@@ -65,9 +63,7 @@ private
end
def local_copy_tag
- Dir.chdir(local_copy_path) do
- sys_exec!("git rev-parse --abbrev-ref HEAD")
- end
+ sys_exec!("git rev-parse --abbrev-ref HEAD", :dir => local_copy_path)
end
def local_copy_path