summaryrefslogtreecommitdiff
path: root/spec/support/helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/helpers.rb')
-rw-r--r--spec/support/helpers.rb62
1 files changed, 28 insertions, 34 deletions
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index e9c9e766cf..dde8daaf6f 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -59,18 +59,6 @@ module Spec
last_command.exitstatus
end
- def in_app_root(&blk)
- Dir.chdir(bundled_app, &blk)
- end
-
- def in_app_root2(&blk)
- Dir.chdir(bundled_app2, &blk)
- end
-
- def in_app_root_custom(root, &blk)
- Dir.chdir(root, &blk)
- end
-
def run(cmd, *args)
opts = args.last.is_a?(Hash) ? args.pop : {}
groups = args.map(&:inspect).join(", ")
@@ -84,7 +72,7 @@ module Spec
begin
#{ruby}
rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR" if e.message.include?("-- #{name}")
+ warn "ZOMG LOAD ERROR" if e.message.include?("-- #{name}")
end
RUBY
opts = args.last.is_a?(Hash) ? args.pop : {}
@@ -92,7 +80,7 @@ module Spec
run(cmd, *args)
end
- def bundle(cmd, options = {})
+ def bundle(cmd, options = {}, &block)
with_sudo = options.delete(:sudo)
sudo = with_sudo == :preserve_env ? "sudo -E" : "sudo" if with_sudo
@@ -126,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
@@ -140,7 +130,7 @@ module Spec
end.join
cmd = "#{sudo} #{Gem.ruby} #{load_path_str} #{requires_str} #{bundle_bin} #{cmd}#{args}"
- sys_exec(cmd, env) {|i, o, thr| yield i, o, thr if block_given? }
+ sys_exec(cmd, { :env => env, :dir => dir }, &block)
end
bang :bundle
@@ -167,10 +157,8 @@ module Spec
end
def ruby(ruby, options = {})
- env = options.delete(:env) || {}
- ruby = ruby.gsub(/["`\$]/) {|m| "\\#{m}" }
lib_option = options[:no_lib] ? "" : " -I#{lib_dir}"
- sys_exec(%(#{Gem.ruby}#{lib_option} -w -e "#{ruby}"), env)
+ sys_exec(%(#{Gem.ruby}#{lib_option} -w -e #{ruby.shellescape}), options)
end
bang :ruby
@@ -179,22 +167,22 @@ module Spec
begin
#{ruby}
rescue LoadError => e
- $stderr.puts "ZOMG LOAD ERROR"# if e.message.include?("-- #{name}")
+ warn "ZOMG LOAD ERROR" if e.message.include?("-- #{name}")
end
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, args = "")
- sys_exec("#{Path.gem_bin} #{command} #{args}")
+ def gem_command(command, options = {})
+ sys_exec("#{Path.gem_bin} #{command}", options)
end
bang :gem_command
@@ -202,11 +190,14 @@ module Spec
"#{Gem.ruby} -S #{ENV["GEM_PATH"]}/bin/rake"
end
- def sys_exec(cmd, env = {})
- command_execution = CommandExecution.new(cmd.to_s, Dir.pwd)
+ def sys_exec(cmd, options = {})
+ env = options[:env] || {}
+ dir = options[:dir] || bundled_app
+ command_execution = CommandExecution.new(cmd.to_s, dir)
require "open3"
- Open3.popen3(env, cmd.to_s) do |stdin, stdout, stderr, wait_thr|
+ require "shellwords"
+ Open3.popen3(env, *cmd.shellsplit, :chdir => dir) do |stdin, stdout, stderr, wait_thr|
yield stdin, stdout, wait_thr if block_given?
stdin.close
@@ -250,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
@@ -260,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
@@ -293,7 +284,7 @@ module Spec
gems.each do |g|
if g == :bundler
with_built_bundler {|gem_path| install_gem(gem_path) }
- elsif g.to_s =~ %r{\A(?:[A-Z]:)?/.*\.gem\z}
+ elsif g.to_s =~ %r{\A(?:[a-zA-Z]:)?/.*\.gem\z}
install_gem(g)
else
install_gem("#{gem_repo}/gems/#{g}.gem")
@@ -304,12 +295,12 @@ module Spec
def install_gem(path)
raise "OMG `#{path}` does not exist!" unless File.exist?(path)
- gem_command! :install, "--no-document --ignore-dependencies '#{path}'"
+ gem_command! "install --no-document --ignore-dependencies '#{path}'"
end
def with_built_bundler
with_root_gemspec do |gemspec|
- Dir.chdir(root) { gem_command! :build, gemspec.to_s }
+ gem_command! "build #{gemspec}", :dir => root
end
bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
@@ -356,6 +347,8 @@ module Spec
end
def with_fake_man
+ skip "fake_man is not a Windows friendly binstub" if Gem.win_platform?
+
FileUtils.mkdir_p(tmp("fake_man"))
File.open(tmp("fake_man/man"), "w", 0o755) do |f|
f.puts "#!/usr/bin/env ruby\nputs ARGV.inspect\n"
@@ -367,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
@@ -416,7 +410,7 @@ module Spec
ENV["GEM_PATH"] = system_gem_path.to_s
gems.each do |gem|
- gem_command! :install, "--no-document #{gem}"
+ gem_command! "install --no-document #{gem}"
end
return unless block_given?
begin
@@ -504,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)