summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 06:15:44 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-12 06:15:44 +0000
commita1a20cfaa2cf73ae8daaf2123d7c5b513427162e (patch)
tree7f112577119ebda6c3dfd71cbc24f1bc559280ae /spec
parentf1c33950998bf2d38d9416aa4f5dfe7f9f869f86 (diff)
Merge 1-16-stable branch of bundler.
It's rc version for bundler-1.16.1. I'm going to update it version after official release from bundler team. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec')
-rw-r--r--spec/bundler/bundler/fetcher_spec.rb12
-rw-r--r--spec/bundler/commands/binstubs_spec.rb19
-rw-r--r--spec/bundler/commands/init_spec.rb66
-rw-r--r--spec/bundler/commands/update_spec.rb17
-rw-r--r--spec/bundler/plugins/source/example_spec.rb4
-rw-r--r--spec/bundler/realworld/double_check_spec.rb42
-rw-r--r--spec/bundler/resolver/basic_spec.rb7
-rw-r--r--spec/bundler/runtime/executable_spec.rb29
-rw-r--r--spec/bundler/runtime/inline_spec.rb4
-rw-r--r--spec/bundler/runtime/with_clean_env_spec.rb2
-rw-r--r--spec/bundler/spec_helper.rb7
-rw-r--r--spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/request7
-rw-r--r--spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/responsebin0 -> 254790 bytes
-rw-r--r--spec/bundler/support/builders.rb2
-rw-r--r--spec/bundler/support/indexes.rb15
-rw-r--r--spec/bundler/support/rubygems_ext.rb3
-rw-r--r--spec/bundler/update/git_spec.rb2
17 files changed, 197 insertions, 41 deletions
diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb
index f9e52e09c0..184b9efa64 100644
--- a/spec/bundler/bundler/fetcher_spec.rb
+++ b/spec/bundler/bundler/fetcher_spec.rb
@@ -95,11 +95,15 @@ RSpec.describe Bundler::Fetcher do
context "when bunder ssl ssl configuration is set" do
before do
+ cert = File.join(Spec::Path.tmpdir, "cert")
+ File.open(cert, "w") {|f| f.write "PEM" }
allow(Bundler.settings).to receive(:[]).and_return(nil)
- allow(Bundler.settings).to receive(:[]).with(:ssl_client_cert).and_return("/cert")
- expect(File).to receive(:read).with("/cert").and_return("")
- expect(OpenSSL::X509::Certificate).to receive(:new).and_return("cert")
- expect(OpenSSL::PKey::RSA).to receive(:new).and_return("key")
+ allow(Bundler.settings).to receive(:[]).with(:ssl_client_cert).and_return(cert)
+ expect(OpenSSL::X509::Certificate).to receive(:new).with("PEM").and_return("cert")
+ expect(OpenSSL::PKey::RSA).to receive(:new).with("PEM").and_return("key")
+ end
+ after do
+ FileUtils.rm File.join(Spec::Path.tmpdir, "cert")
end
it "use bundler configuration" do
expect(fetcher.send(:connection).cert).to eq("cert")
diff --git a/spec/bundler/commands/binstubs_spec.rb b/spec/bundler/commands/binstubs_spec.rb
index 0313f48b60..ec402c327c 100644
--- a/spec/bundler/commands/binstubs_spec.rb
+++ b/spec/bundler/commands/binstubs_spec.rb
@@ -50,6 +50,25 @@ RSpec.describe "bundle binstubs <gem>" do
expect(out).to include("`bundle binstubs` needs at least one gem to run.")
end
+ context "when generating bundle binstub outside bundler" do
+ it "should abort" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ bundle "binstubs rack"
+
+ File.open("bin/bundle", "wb") do |file|
+ file.print "OMG"
+ end
+
+ sys_exec "bin/rackup"
+
+ expect(last_command.stderr).to include("was not generated by Bundler")
+ end
+ end
+
context "the bundle binstub" do
before do
if system_bundler_version == :bundler
diff --git a/spec/bundler/commands/init_spec.rb b/spec/bundler/commands/init_spec.rb
index 0441e62e13..c1cd7b90c8 100644
--- a/spec/bundler/commands/init_spec.rb
+++ b/spec/bundler/commands/init_spec.rb
@@ -13,9 +13,9 @@ RSpec.describe "bundle init" do
expect(bundled_app("gems.rb")).to be_file
end
- context "when a Gemfile already exists" do
+ context "when a Gemfile already exists", :bundler => "< 2" do
before do
- gemfile <<-G
+ create_file "Gemfile", <<-G
gem "rails"
G
end
@@ -30,14 +30,14 @@ RSpec.describe "bundle init" do
end
end
- context "when a gems.rb already exists" do
+ context "when gems.rb already exists", :bundler => ">= 2" do
before do
- create_file "gems.rb", <<-G
+ create_file("gems.rb", <<-G)
gem "rails"
G
end
- it "does not change existing gem.rb files" do
+ it "does not change existing Gemfiles" do
expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
end
@@ -47,6 +47,40 @@ RSpec.describe "bundle init" do
end
end
+ context "when a Gemfile exists in a parent directory", :bundler => "< 2" do
+ let(:subdir) { "child_dir" }
+
+ it "lets users generate a Gemfile in a child directory" do
+ bundle! :init
+
+ FileUtils.mkdir bundled_app(subdir)
+
+ Dir.chdir bundled_app(subdir) do
+ bundle! :init
+ end
+
+ expect(out).to include("Writing new Gemfile")
+ expect(bundled_app("#{subdir}/Gemfile")).to be_file
+ end
+ end
+
+ context "when a gems.rb file exists in a parent directory", :bundler => ">= 2" do
+ let(:subdir) { "child_dir" }
+
+ it "lets users generate a Gemfile in a child directory" do
+ bundle! :init
+
+ FileUtils.mkdir bundled_app(subdir)
+
+ Dir.chdir bundled_app(subdir) do
+ bundle! :init
+ end
+
+ expect(out).to include("Writing new gems.rb")
+ expect(bundled_app("#{subdir}/gems.rb")).to be_file
+ end
+ end
+
context "given --gemspec option", :bundler => "< 2" do
let(:spec_file) { tmp.join("test.gemspec") }
@@ -94,28 +128,6 @@ RSpec.describe "bundle init" do
context "when init_gems_rb setting is enabled" do
before { bundle "config init_gems_rb true" }
- it "generates a gems.rb file" do
- bundle :init
- expect(bundled_app("gems.rb")).to exist
- end
-
- context "when gems.rb already exists" do
- before do
- create_file("gems.rb", <<-G)
- gem "rails"
- G
- end
-
- it "does not change existing Gemfiles" do
- expect { bundle :init }.not_to change { File.read(bundled_app("gems.rb")) }
- end
-
- it "notifies the user that an existing gems.rb already exists" do
- bundle :init
- expect(out).to include("gems.rb already exists")
- end
- end
-
context "given --gemspec option", :bundler => "< 2" do
let(:spec_file) { tmp.join("test.gemspec") }
diff --git a/spec/bundler/commands/update_spec.rb b/spec/bundler/commands/update_spec.rb
index a8283cf593..a2842f0998 100644
--- a/spec/bundler/commands/update_spec.rb
+++ b/spec/bundler/commands/update_spec.rb
@@ -195,6 +195,23 @@ RSpec.describe "bundle update" do
expect(the_bundle).not_to include_gems "foo 2.0"
end
end
+
+ context "when bundler itself is a transitive dependency" do
+ it "executes without error" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "activesupport", :group => :development
+ gem "rack"
+ G
+ update_repo2 do
+ build_gem "activesupport", "3.0"
+ end
+ bundle "update --group development"
+ expect(the_bundle).to include_gems "activesupport 2.3.5"
+ expect(the_bundle).to include_gems "bundler #{Bundler::VERSION}"
+ expect(the_bundle).not_to include_gems "rack 1.2"
+ end
+ end
end
describe "in a frozen bundle" do
diff --git a/spec/bundler/plugins/source/example_spec.rb b/spec/bundler/plugins/source/example_spec.rb
index 2b59244782..fd30892f63 100644
--- a/spec/bundler/plugins/source/example_spec.rb
+++ b/spec/bundler/plugins/source/example_spec.rb
@@ -97,7 +97,7 @@ RSpec.describe "real source plugins" do
lockfile_should_be <<-G
GEM
- remote: file:#{gem_repo2}/
+ remote: file://localhost#{gem_repo2}/
specs:
PLUGIN SOURCE
@@ -392,7 +392,7 @@ RSpec.describe "real source plugins" do
lockfile_should_be <<-G
GEM
- remote: file:#{gem_repo2}/
+ remote: file://localhost#{gem_repo2}/
specs:
PLUGIN SOURCE
diff --git a/spec/bundler/realworld/double_check_spec.rb b/spec/bundler/realworld/double_check_spec.rb
new file mode 100644
index 0000000000..0aa58b3de3
--- /dev/null
+++ b/spec/bundler/realworld/double_check_spec.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+RSpec.describe "double checking sources", :realworld => true do
+ if RUBY_VERSION >= "2.2" # rails 5.x and rack 2.x only supports >= Ruby 2.2.
+ it "finds already-installed gems" do
+ create_file("rails.gemspec", <<-RUBY)
+ Gem::Specification.new do |s|
+ s.name = "rails"
+ s.version = "5.1.4"
+ s.summary = ""
+ s.description = ""
+ s.author = ""
+ s.add_dependency "actionpack", "5.1.4"
+ end
+ RUBY
+
+ create_file("actionpack.gemspec", <<-RUBY)
+ Gem::Specification.new do |s|
+ s.name = "actionpack"
+ s.version = "5.1.4"
+ s.summary = ""
+ s.description = ""
+ s.author = ""
+ s.add_dependency "rack", "~> 2.0.0"
+ end
+ RUBY
+
+ cmd = <<-RUBY
+ require "bundler"
+ require #{File.expand_path("../../support/artifice/vcr.rb", __FILE__).dump}
+ require "bundler/inline"
+ gemfile(true) do
+ source "https://rubygems.org"
+ gem "rails", path: "."
+ end
+ RUBY
+
+ ruby! cmd
+ ruby! cmd
+ end
+ end
+end
diff --git a/spec/bundler/resolver/basic_spec.rb b/spec/bundler/resolver/basic_spec.rb
index d5658824ba..623d092644 100644
--- a/spec/bundler/resolver/basic_spec.rb
+++ b/spec/bundler/resolver/basic_spec.rb
@@ -42,6 +42,13 @@ RSpec.describe "Resolving" do
should_resolve_as %w[a-1.0.0 b-2.0.0 c-1.0.0 d-1.0.0]
end
+ it "prefers non-prerelease resolutions in sort order" do
+ @index = optional_prereleases_index
+ dep "a"
+ dep "b"
+ should_resolve_as %w[a-1.0.0 b-1.5.0]
+ end
+
it "resolves a index with root level conflict on child" do
@index = a_index_with_root_conflict_on_child
dep "i18n", "~> 0.4"
diff --git a/spec/bundler/runtime/executable_spec.rb b/spec/bundler/runtime/executable_spec.rb
index 388ee049d0..dcee234e15 100644
--- a/spec/bundler/runtime/executable_spec.rb
+++ b/spec/bundler/runtime/executable_spec.rb
@@ -158,4 +158,33 @@ RSpec.describe "Running bin/* commands" do
expect(bundled_app("bin/rackup").read).to_not eq("OMG")
end
+
+ it "use BUNDLE_GEMFILE gemfile for binstub" do
+ # context with bin/bunlder w/ default Gemfile
+ bundle! "binstubs bundler"
+
+ # generate other Gemfile with executable gem
+ build_repo2 do
+ build_gem("bindir") {|s| s.executables = "foo" }
+ end
+
+ create_file("OtherGemfile", <<-G)
+ source "file://#{gem_repo2}"
+ gem 'bindir'
+ G
+
+ # generate binstub for executable from non default Gemfile (other then bin/bundler version)
+ ENV["BUNDLE_GEMFILE"] = "OtherGemfile"
+ bundle "install"
+ bundle! "binstubs bindir"
+
+ # remove user settings
+ ENV["BUNDLE_GEMFILE"] = nil
+
+ # run binstub for non default Gemfile
+ gembin "foo"
+
+ expect(exitstatus).to eq(0) if exitstatus
+ expect(out).to eq("1.0")
+ end
end
diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb
index dcaba3ab9d..18ca246199 100644
--- a/spec/bundler/runtime/inline_spec.rb
+++ b/spec/bundler/runtime/inline_spec.rb
@@ -43,10 +43,6 @@ RSpec.describe "bundler/inline#gemfile" do
build_lib "eight", "1.0.0" do |s|
s.write "lib/eight.rb", "puts 'eight'"
end
-
- build_lib "four", "1.0.0" do |s|
- s.write "lib/four.rb", "puts 'four'"
- end
end
it "requires the gems" do
diff --git a/spec/bundler/runtime/with_clean_env_spec.rb b/spec/bundler/runtime/with_clean_env_spec.rb
index 55e45460db..05b334c28a 100644
--- a/spec/bundler/runtime/with_clean_env_spec.rb
+++ b/spec/bundler/runtime/with_clean_env_spec.rb
@@ -80,7 +80,7 @@ RSpec.describe "Bundler.with_env helpers" do
it "should clean up RUBYLIB", :ruby_repo do
code = "print Bundler.clean_env['RUBYLIB']"
ENV["RUBYLIB"] = root.join("lib").to_s + File::PATH_SEPARATOR + "/foo"
- result = bundle("exec ruby -e #{code.inspect}")
+ result = bundle("exec '#{Gem.ruby}' -e #{code.inspect}")
expect(result).to eq("/foo")
end
diff --git a/spec/bundler/spec_helper.rb b/spec/bundler/spec_helper.rb
index 37061ffb87..7731435f3b 100644
--- a/spec/bundler/spec_helper.rb
+++ b/spec/bundler/spec_helper.rb
@@ -99,6 +99,8 @@ RSpec.configure do |config|
original_wd = Dir.pwd
original_env = ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) }
+ original_default_specs = Dir[File.join(Gem.default_dir, "specifications", "default", "bundler*")]
+ original_site_ruby_dirs = $LOAD_PATH.select {|path| path =~ /site_ruby/ }.map {|path| File.join(path, "bundler*") }.compact.map {|path| Dir[path] }.flatten
config.expect_with :rspec do |c|
c.syntax = :expect
@@ -113,6 +115,11 @@ RSpec.configure do |config|
config.before :all do
build_repo1
+ (original_default_specs + original_site_ruby_dirs).each {|s| FileUtils.mv(s, s + ".org") }
+ end
+
+ config.after :all do
+ (original_default_specs + original_site_ruby_dirs).each {|s| FileUtils.mv(s + ".org", s) if File.exist?(s + ".org") }
end
config.before :each do
diff --git a/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/request b/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/request
new file mode 100644
index 0000000000..ed63e334fa
--- /dev/null
+++ b/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/request
@@ -0,0 +1,7 @@
+> GET /gems/rack-2.0.1.gem
+> accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+> accept: */*
+> user-agent: Ruby
+> connection: keep-alive
+> keep-alive: 30
+> host: rubygems.org \ No newline at end of file
diff --git a/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/response b/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/response
new file mode 100644
index 0000000000..4e2fc2b8cd
--- /dev/null
+++ b/spec/bundler/support/artifice/vcr_cassettes/realworld/rubygems.org/gems/rack-2.0.1.gem/GET/response
Binary files differ
diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb
index e8208eacd9..377ca35523 100644
--- a/spec/bundler/support/builders.rb
+++ b/spec/bundler/support/builders.rb
@@ -391,7 +391,7 @@ module Spec
index
end
- def build_spec(name, version, platform = nil, &block)
+ def build_spec(name, version = "0.0.1", platform = nil, &block)
Array(version).map do |v|
Gem::Specification.new do |s|
s.name = name
diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb
index 05605195b1..c56d6145a7 100644
--- a/spec/bundler/support/indexes.rb
+++ b/spec/bundler/support/indexes.rb
@@ -401,5 +401,20 @@ module Spec
gem("d", %w[1.0.0 2.0.0])
end
end
+
+ def optional_prereleases_index
+ build_index do
+ gem("a", %w[1.0.0])
+
+ gem("a", "2.0.0") do
+ dep "b", ">= 2.0.0.pre"
+ end
+
+ gem("b", %w[0.9.0 1.5.0 2.0.0.pre])
+
+ # --- Pre-release support
+ gem "rubygems\0", ["1.3.2"]
+ end
+ end
end
end
diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb
index 73e90f6883..c174c76636 100644
--- a/spec/bundler/support/rubygems_ext.rb
+++ b/spec/bundler/support/rubygems_ext.rb
@@ -54,7 +54,8 @@ module Spec
def self.install_gems(gems)
reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? }
- reqs = reqs.sort_by {|name, _| name == "rack" ? 0 : 1 } # TODO: remove when we drop ruby 1.8.7 support
+ # TODO: remove when we drop ruby 1.8.7-2.2.2 support
+ reqs = reqs.sort_by {|name, _| name == "rack" ? 0 : 1 }.sort_by {|name, _| name =~ /rack/ ? 0 : 1 }
no_reqs.map!(&:first)
reqs.map! {|name, req| "'#{name}:#{req}'" }
deps = reqs.concat(no_reqs).join(" ")
diff --git a/spec/bundler/update/git_spec.rb b/spec/bundler/update/git_spec.rb
index f8a6f534ee..b4cbb79434 100644
--- a/spec/bundler/update/git_spec.rb
+++ b/spec/bundler/update/git_spec.rb
@@ -349,7 +349,7 @@ RSpec.describe "bundle update" do
lockfile_should_be <<-G
GEM
- remote: file:#{gem_repo2}/
+ remote: file://localhost#{gem_repo2}/
specs:
rack (1.0.0)