summaryrefslogtreecommitdiff
path: root/spec/bundler/support/builders.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/support/builders.rb')
-rw-r--r--spec/bundler/support/builders.rb157
1 files changed, 85 insertions, 72 deletions
diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb
index b3f5f9b876..5ce6e01da3 100644
--- a/spec/bundler/support/builders.rb
+++ b/spec/bundler/support/builders.rb
@@ -17,6 +17,18 @@ module Spec
Gem::Platform.new(platform)
end
+ # Returns a number smaller than the size of the index. Useful for specs that
+ # need the API request limit to be reached for some reason.
+ def low_api_request_limit_for(gem_repo)
+ all_gems = Dir[gem_repo.join("gems/*.gem")]
+
+ all_gem_names = all_gems.map do |file|
+ File.basename(file, ".gem").match(/\A(?<gem_name>[^-]+)-.*\z/)[:gem_name]
+ end.uniq
+
+ (all_gem_names - ["bundler"]).size
+ end
+
def build_repo1
build_repo gem_repo1 do
build_gem "rack", %w[0.9.1 1.0.0] do |s|
@@ -40,7 +52,7 @@ module Spec
build_gem "rails", "2.3.2" do |s|
s.executables = "rails"
- s.add_dependency "rake", "12.3.2"
+ s.add_dependency "rake", "13.0.1"
s.add_dependency "actionpack", "2.3.2"
s.add_dependency "activerecord", "2.3.2"
s.add_dependency "actionmailer", "2.3.2"
@@ -302,6 +314,18 @@ module Spec
end
RUBY
end
+
+ build_gem "has_metadata" do |s|
+ s.metadata = {
+ "bug_tracker_uri" => "https://example.com/user/bestgemever/issues",
+ "changelog_uri" => "https://example.com/user/bestgemever/CHANGELOG.md",
+ "documentation_uri" => "https://www.example.info/gems/bestgemever/0.0.1",
+ "homepage_uri" => "https://bestgemever.example.io",
+ "mailing_list_uri" => "https://groups.example.com/bestgemever",
+ "source_code_uri" => "https://example.com/user/bestgemever",
+ "wiki_uri" => "https://example.com/user/bestgemever/wiki",
+ }
+ end
end
end
@@ -358,8 +382,8 @@ module Spec
rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first
if rake_path.nil?
- Spec::Path.base_system_gems.rmtree
- Spec::Rubygems.setup
+ FileUtils.rm_rf(Path.base_system_gems)
+ Spec::Rubygems.install_test_deps
rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first
end
@@ -382,7 +406,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
@@ -424,13 +448,13 @@ module Spec
opts = args.last.is_a?(Hash) ? args.last : {}
builder = opts[:bare] ? GitBareBuilder : GitBuilder
spec = build_with(builder, name, args, &block)
- GitReader.new(opts[:path] || lib_path(spec.full_name))
+ GitReader.new(self, opts[:path] || lib_path(spec.full_name))
end
def update_git(name, *args, &block)
opts = args.last.is_a?(Hash) ? args.last : {}
spec = build_with(GitUpdater, name, args, &block)
- GitReader.new(opts[:path] || lib_path(spec.full_name))
+ GitReader.new(self, opts[:path] || lib_path(spec.full_name))
end
def build_plugin(name, *args, &blk)
@@ -451,7 +475,6 @@ module Spec
Array(versions).each do |version|
spec = builder.new(self, name, version)
- spec.authors = ["no one"] if !spec.authors || spec.authors.empty?
yield spec if block_given?
spec._build(options)
end
@@ -599,15 +622,6 @@ module Spec
def @spec.validate(*); end
end
- case options[:gemspec]
- when false
- # do nothing
- when :yaml
- @files["#{name}.gemspec"] = @spec.to_yaml
- else
- @files["#{name}.gemspec"] = @spec.to_ruby
- end
-
unless options[:no_default]
gem_source = options[:source] || "path@#{path}"
@files = _default_files.
@@ -616,13 +630,24 @@ module Spec
end
@spec.authors = ["no one"]
+ @spec.files = @files.keys
+
+ case options[:gemspec]
+ when false
+ # do nothing
+ when :yaml
+ @spec.files << "#{name}.gemspec"
+ @files["#{name}.gemspec"] = @spec.to_yaml
+ else
+ @spec.files << "#{name}.gemspec"
+ @files["#{name}.gemspec"] = @spec.to_ruby
+ end
@files.each do |file, source|
file = Pathname.new(path).join(file)
FileUtils.mkdir_p(file.dirname)
File.open(file, "w") {|f| f.puts source }
end
- @spec.files = @files.keys
path
end
@@ -648,14 +673,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
+ @context.git("init", path)
+ @context.git("add *", path)
+ @context.git("config user.email lol@wut.com", path)
+ @context.git("config user.name lolwut", path)
+ @context.git("config commit.gpgsign false", path)
+ @context.git("commit -m OMG_INITIAL_COMMIT", path)
end
end
@@ -663,91 +686,81 @@ module Spec
def _build(options)
path = options[:path] || _default_path
super(options.merge(:path => path))
- Dir.chdir(path) do
- `git init --bare`
- end
+ @context.git("init --bare", path)
end
end
class GitUpdater < LibBuilder
- def silently(str)
- `#{str} 2>#{Bundler::NULL}`
- end
-
def _build(options)
libpath = options[:path] || _default_path
update_gemspec = options[:gemspec] || false
source = options[:source] || "git@#{libpath}"
- Dir.chdir(libpath) do
- silently "git checkout master"
+ @context.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 @context.git("branch -l #{escaped_branch}", libpath).empty?
+ @context.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"`
+ @context.git("checkout #{escaped_branch}", libpath)
+ elsif tag = options[:tag]
+ @context.git("tag #{Shellwords.shellescape(tag)}", libpath)
+ elsif options[:remote]
+ @context.git("remote add origin #{options[:remote]}", libpath)
+ elsif options[:push]
+ @context.git("push origin #{options[:push]}", libpath)
end
+
+ current_ref = @context.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))
+ @context.git("add *", libpath)
+ @context.git("commit -m BUMP", libpath)
end
end
class GitReader
- attr_reader :path
+ attr_reader :context, :path
- def initialize(path)
+ def initialize(context, path)
+ @context = context
@path = path
end
def ref_for(ref, len = nil)
- ref = git "rev-parse #{ref}"
+ ref = context.git "rev-parse #{ref}", path
ref = ref[0..len] if len
ref
end
-
- private
-
- def git(cmd)
- Bundler::SharedHelpers.with_clean_git_env do
- Dir.chdir(@path) { `git #{cmd}`.strip }
- end
- end
end
class GemBuilder < LibBuilder
def _build(opts)
lib_path = super(opts.merge(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default]))
destination = opts[:path] || _default_path
- Dir.chdir(lib_path) do
- FileUtils.mkdir_p(destination)
-
- @spec.authors = ["that guy"] if !@spec.authors || @spec.authors.empty?
+ FileUtils.mkdir_p(lib_path.join(destination))
- Bundler.rubygems.build(@spec, opts[:skip_validation])
+ if opts[:gemspec] == :yaml || opts[:gemspec] == false
+ Dir.chdir(lib_path) do
+ Bundler.rubygems.build(@spec, opts[:skip_validation])
+ end
+ elsif opts[:skip_validation]
+ @context.gem_command "build --force #{@spec.name}", :dir => lib_path
+ else
+ @context.gem_command! "build #{@spec.name}", :dir => lib_path
end
+
gem_path = File.expand_path("#{@spec.full_name}.gem", lib_path)
if opts[:to_system]
@context.system_gems gem_path, :keep_path => true
elsif opts[:to_bundle]
- @context.system_gems gem_path, :path => :bundle_path, :keep_path => true
+ @context.system_gems gem_path, :path => @context.default_bundle_path, :keep_path => true
else
FileUtils.mv(gem_path, destination)
end