summaryrefslogtreecommitdiff
path: root/spec/support/builders.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/builders.rb')
-rw-r--r--spec/support/builders.rb96
1 files changed, 52 insertions, 44 deletions
diff --git a/spec/support/builders.rb b/spec/support/builders.rb
index 76c9fff463..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
@@ -623,7 +628,7 @@ module Spec
unless options[:no_default]
gem_source = options[:source] || "path@#{path}"
@files = _default_files.
- merge("lib/#{name}/source.rb" => "#{Builders.constantize(name)}_SOURCE = #{gem_source.to_s.dump}").
+ merge("lib/#{entrypoint}/source.rb" => "#{Builders.constantize(name)}_SOURCE = #{gem_source.to_s.dump}").
merge(@files)
end
@@ -639,15 +644,20 @@ module Spec
end
def _default_files
- @_default_files ||= begin
- platform_string = " #{@spec.platform}" unless @spec.platform == Gem::Platform::RUBY
- { "lib/#{name}.rb" => "#{Builders.constantize(name)} = '#{version}#{platform_string}'" }
- end
+ @_default_files ||= { "lib/#{entrypoint}.rb" => "#{Builders.constantize(name)} = '#{version}#{platform_string}'" }
+ end
+
+ def entrypoint
+ name.tr("-", "/")
end
def _default_path
@context.tmp("libs", @spec.full_name)
end
+
+ def platform_string
+ " #{@spec.platform}" unless @spec.platform == Gem::Platform::RUBY
+ end
end
class GitBuilder < LibBuilder
@@ -655,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
@@ -670,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)
@@ -686,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 `git branch | grep #{escaped_branch}`.empty?
- silently("git branch #{escaped_branch}")
- end
+ if branch = options[:branch]
+ raise "You can't specify `master` as the branch" if branch == "master"
+ escaped_branch = Shellwords.shellescape(branch)
- 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
@@ -734,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
@@ -767,7 +772,10 @@ module Spec
class PluginBuilder < GemBuilder
def _default_files
- @_default_files ||= super.merge("plugins.rb" => "")
+ @_default_files ||= {
+ "lib/#{name}.rb" => "#{Builders.constantize(name)} = '#{version}#{platform_string}'",
+ "plugins.rb" => "",
+ }
end
end