aboutsummaryrefslogtreecommitdiffstats
path: root/spec/bundler/bundler
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-08 14:19:04 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-13 07:54:37 +0900
commit0e60b59d5884edb8f9aea023efd9b24f1ff02049 (patch)
treee52935ce510440872ca5ce6b0e092cbc94f18bc9 /spec/bundler/bundler
parent68224651a4d4dc3ce0cea666f5423dd8b6ba6cfc (diff)
downloadruby-0e60b59d5884edb8f9aea023efd9b24f1ff02049.tar.gz
Update the bundler version with master branch
Diffstat (limited to 'spec/bundler/bundler')
-rw-r--r--spec/bundler/bundler/bundler_spec.rb22
-rw-r--r--spec/bundler/bundler/cli_spec.rb12
-rw-r--r--spec/bundler/bundler/compact_index_client/gem_parser_spec.rb174
-rw-r--r--spec/bundler/bundler/compact_index_client/updater_spec.rb6
-rw-r--r--spec/bundler/bundler/definition_spec.rb10
-rw-r--r--spec/bundler/bundler/dsl_spec.rb44
-rw-r--r--spec/bundler/bundler/env_spec.rb34
-rw-r--r--spec/bundler/bundler/fetcher/compact_index_spec.rb3
-rw-r--r--spec/bundler/bundler/fetcher_spec.rb3
-rw-r--r--spec/bundler/bundler/friendly_errors_spec.rb83
-rw-r--r--spec/bundler/bundler/gem_helper_spec.rb63
-rw-r--r--spec/bundler/bundler/mirror_spec.rb2
-rw-r--r--spec/bundler/bundler/plugin/index_spec.rb11
-rw-r--r--spec/bundler/bundler/plugin_spec.rb9
-rw-r--r--spec/bundler/bundler/settings_spec.rb2
-rw-r--r--spec/bundler/bundler/shared_helpers_spec.rb42
-rw-r--r--spec/bundler/bundler/source/git/git_proxy_spec.rb5
17 files changed, 342 insertions, 183 deletions
diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb
index 247838600b..56ef4ce75a 100644
--- a/spec/bundler/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler/bundler_spec.rb
@@ -124,7 +124,15 @@ RSpec.describe Bundler do
describe "#which" do
let(:executable) { "executable" }
- let(:path) { %w[/a /b c ../d /e] }
+
+ let(:path) do
+ if Gem.win_platform?
+ %w[C:/a C:/b C:/c C:/../d C:/e]
+ else
+ %w[/a /b c ../d /e]
+ end
+ end
+
let(:expected) { "executable" }
before do
@@ -149,7 +157,13 @@ RSpec.describe Bundler do
it_behaves_like "it returns the correct executable"
context "when the executable in inside a quoted path" do
- let(:expected) { "/e/executable" }
+ let(:expected) do
+ if Gem.win_platform?
+ "C:/e/executable"
+ else
+ "/e/executable"
+ end
+ end
it_behaves_like "it returns the correct executable"
end
@@ -196,6 +210,8 @@ EOF
gem "rack"
G
+ allow(Bundler).to receive(:root).and_return(bundled_app)
+
Bundler.mkdir_p(bundled_app.join("foo", "bar"))
expect(bundled_app.join("foo", "bar")).to exist
end
@@ -322,7 +338,7 @@ EOF
end
context "with unwritable files in a parent dir" do
- # Regression test for https://github.com/bundler/bundler/pull/6316
+ # Regression test for https://github.com/rubygems/bundler/pull/6316
# It doesn't matter if there are other unwritable files so long as
# bundle_path can be created
before do
diff --git a/spec/bundler/bundler/cli_spec.rb b/spec/bundler/bundler/cli_spec.rb
index ddcd699d6c..a56e148e89 100644
--- a/spec/bundler/bundler/cli_spec.rb
+++ b/spec/bundler/bundler/cli_spec.rb
@@ -14,6 +14,8 @@ RSpec.describe "bundle executable" do
end
it "looks for a binary and executes it if it's named bundler-<task>" do
+ skip "obscure error" if Gem.win_platform?
+
File.open(tmp("bundler-testtasks"), "w", 0o755) do |f|
ruby = ENV["RUBY"] || "/usr/bin/env ruby"
f.puts "#!#{ruby}\nputs 'Hello, world'\n"
@@ -91,7 +93,7 @@ RSpec.describe "bundle executable" do
context "when ENV['BUNDLE_GEMFILE'] is set to an empty string" do
it "ignores it" do
- gemfile bundled_app("Gemfile"), <<-G
+ gemfile bundled_app_gemfile, <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'rack'
G
@@ -104,7 +106,7 @@ RSpec.describe "bundle executable" do
context "when ENV['RUBYGEMS_GEMDEPS'] is set" do
it "displays a warning" do
- gemfile bundled_app("Gemfile"), <<-G
+ gemfile bundled_app_gemfile, <<-G
source "#{file_uri_for(gem_repo1)}"
gem 'rack'
G
@@ -149,7 +151,7 @@ RSpec.describe "bundle executable" do
before do
bundle! "config set --global disable_version_check false"
- simulate_bundler_version(bundler_version)
+ system_gems "bundler-#{bundler_version}"
if latest_version
info_path = home(".bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/info/bundler")
info_path.parent.mkpath
@@ -174,7 +176,7 @@ RSpec.describe "bundle executable" do
context "when the latest version is greater than the current version" do
let(:latest_version) { "222.0" }
it "prints the version warning" do
- bundle "fail"
+ bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" }
expect(err).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To install the latest version, run `gem install bundler`
@@ -199,7 +201,7 @@ To install the latest version, run `gem install bundler`
context "and is a pre-release" do
let(:latest_version) { "222.0.0.pre.4" }
it "prints the version warning" do
- bundle "fail"
+ bundle "fail", :system_bundler => true, :env => { "BUNDLER_SPEC_IGNORE_DEFAULT_BUNDLER_GEM" => "true" }
expect(err).to start_with(<<-EOS.strip)
The latest bundler is #{latest_version}, but you are currently running #{bundler_version}.
To install the latest version, run `gem install bundler --pre`
diff --git a/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb b/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb
new file mode 100644
index 0000000000..5f5305426f
--- /dev/null
+++ b/spec/bundler/bundler/compact_index_client/gem_parser_spec.rb
@@ -0,0 +1,174 @@
+# frozen_string_literal: true
+
+require "bundler/compact_index_client/gem_parser"
+
+RSpec.describe Bundler::CompactIndexClient::GemParser do
+ def parse(line)
+ parser = Bundler::CompactIndexClient::GemParser.new
+ parser.parse(line)
+ end
+
+ context "platform" do
+ it "existent" do
+ checksum = "d5956d2bcb509af2cd07c90d9e5fdb331be8845a75bfd823a31c147b52cff471"
+ line = "1.11.3-java |checksum:#{checksum}"
+ expected = [
+ "1.11.3",
+ "java",
+ [],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ it "nonexistent" do
+ checksum = "6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81"
+ line = "1.11.3 |checksum:#{checksum}"
+ expected = [
+ "1.11.3",
+ nil,
+ [],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+ end
+
+ context "dependencies" do
+ it "nothing" do
+ checksum = "6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81"
+ line = "1.11.3 |checksum:#{checksum}"
+ expected = [
+ "1.11.3",
+ nil,
+ [],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ it "one" do
+ checksum = "5f0b378d12ab5665e2b6a1525274de97350238963002583cf088dae988527647"
+ line = "0.3.2 bones:>= 2.4.2|checksum:#{checksum}"
+ expected = [
+ "0.3.2",
+ nil,
+ [
+ ["bones", [">= 2.4.2"]],
+ ],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ it "multiple" do
+ checksum = "199e892ada86c44d1f2e110b822d5da46b52fa2cbd2f00d89695b4cf610f9927"
+ line = "3.1.2 native-package-installer:>= 0,pkg-config:>= 0|checksum:#{checksum}"
+ expected = [
+ "3.1.2",
+ nil,
+ [
+ ["native-package-installer", [">= 0"]],
+ ["pkg-config", [">= 0"]],
+ ],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ context "version" do
+ it "multiple" do
+ checksum = "1ec894b8090cb2c9393153552be2f3b6b1975265cbc1e0a3c6b28ebfea7e76a1"
+ line = "3.1.5 multi_json:< 1.3&>= 1.0|checksum:#{checksum}"
+ expected = [
+ "3.1.5",
+ nil,
+ [
+ ["multi_json", ["< 1.3", ">= 1.0"]],
+ ],
+ [
+ ["checksum", [checksum]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+ end
+ end
+
+ context "requirements" do
+ context "ruby" do
+ it "one version" do
+ checksum ="6da2eb3c4867e64df28d3e0b1008422dfacda7c046f9a8f3c56c52505b195e81"
+ line = "1.11.3 |checksum:#{checksum},ruby:>= 2.0"
+ expected = [
+ "1.11.3",
+ nil,
+ [],
+ [
+ ["checksum", [checksum]],
+ ["ruby", [">= 2.0"]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ it "multiple versions" do
+ checksum = "99e4845796c8dec1c3fc80dc772860a01633b33291bd7534007f5c7724f0b876"
+ line = "1.11.3-x86-mingw32 |checksum:#{checksum},ruby:>= 2.2, < 2.7.dev"
+ expected = [
+ "1.11.3",
+ "x86-mingw32",
+ [],
+ [
+ ["checksum", [checksum]],
+ ["ruby", [">= 2.2", "< 2.7.dev"]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+
+ it "with rubygems" do
+ checksum = "7a82b358f00da749b01f8c84df8e8eb21c1bc389740aab9a2bf4ce59894564ac"
+ line = "1.9.23.pre1 |checksum:#{checksum},ruby:>= 1.9, < 2.7.dev,rubygems:> 1.3.1"
+ expected = [
+ "1.9.23.pre1",
+ nil,
+ [],
+ [
+ ["checksum", [checksum]],
+ ["ruby", [">= 1.9", "< 2.7.dev"]],
+ ["rubygems", ["> 1.3.1"]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+ end
+
+ context "rubygems" do
+ it "existent" do
+ checksum = "91ddb4c1b5482a4aff957f6733e282ce2767b2d3051138e0203e39d6df4eba10"
+ line = "1.0.12.pre |checksum:#{checksum},rubygems:> 1.3.1"
+ expected = [
+ "1.0.12.pre",
+ nil,
+ [],
+ [
+ ["checksum", [checksum]],
+ ["rubygems", ["> 1.3.1"]],
+ ],
+ ]
+ expect(parse(line)).to eq expected
+ end
+ end
+ end
+end
diff --git a/spec/bundler/bundler/compact_index_client/updater_spec.rb b/spec/bundler/bundler/compact_index_client/updater_spec.rb
index fd554a7b0d..26159dccd8 100644
--- a/spec/bundler/bundler/compact_index_client/updater_spec.rb
+++ b/spec/bundler/bundler/compact_index_client/updater_spec.rb
@@ -9,10 +9,10 @@ RSpec.describe Bundler::CompactIndexClient::Updater do
let(:local_path) { Pathname("/tmp/localpath") }
let(:remote_path) { double(:remote_path) }
- subject(:updater) { described_class.new(fetcher) }
+ let!(:updater) { described_class.new(fetcher) }
context "when the ETag header is missing" do
- # Regression test for https://github.com/bundler/bundler/issues/5463
+ # Regression test for https://github.com/rubygems/bundler/issues/5463
let(:response) { double(:response, :body => "") }
@@ -42,8 +42,6 @@ RSpec.describe Bundler::CompactIndexClient::Updater do
end
context "when bundler doesn't have permissions on Dir.tmpdir" do
- let(:response) { double(:response, :body => "") }
-
it "Errno::EACCES is raised" do
allow(Dir).to receive(:mktmpdir) { raise Errno::EACCES }
diff --git a/spec/bundler/bundler/definition_spec.rb b/spec/bundler/bundler/definition_spec.rb
index 1f4c1a0807..d0ebb37933 100644
--- a/spec/bundler/bundler/definition_spec.rb
+++ b/spec/bundler/bundler/definition_spec.rb
@@ -210,10 +210,12 @@ RSpec.describe Bundler::Definition do
source "#{file_uri_for(gem_repo1)}"
gem "foo"
G
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "should get a locked specs list when updating all" do
- definition = Bundler::Definition.new(bundled_app("Gemfile.lock"), [], Bundler::SourceList.new, true)
+ definition = Bundler::Definition.new(bundled_app_lock, [], Bundler::SourceList.new, true)
locked_specs = definition.gem_version_promoter.locked_specs
expect(locked_specs.to_a.map(&:name)).to eq ["foo"]
expect(definition.instance_variable_get("@locked_specs").empty?).to eq true
@@ -267,6 +269,8 @@ RSpec.describe Bundler::Definition do
BUNDLED WITH
1.13.0
L
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "should not eagerly unlock shared dependency with bundle install conservative updating behavior" do
@@ -275,7 +279,7 @@ RSpec.describe Bundler::Definition do
Bundler::Dependency.new("shared_owner_b", ">= 0")]
unlock_hash_for_bundle_install = {}
definition = Bundler::Definition.new(
- bundled_app("Gemfile.lock"),
+ bundled_app_lock,
updated_deps_in_gemfile,
source_list,
unlock_hash_for_bundle_install
@@ -289,7 +293,7 @@ RSpec.describe Bundler::Definition do
Bundler::Dependency.new("shared_owner_a", ">= 0"),
Bundler::Dependency.new("shared_owner_b", ">= 0")]
definition = Bundler::Definition.new(
- bundled_app("Gemfile.lock"),
+ bundled_app_lock,
updated_deps_in_gemfile,
source_list,
:gems => ["shared_owner_a"], :lock_shared_dependencies => true
diff --git a/spec/bundler/bundler/dsl_spec.rb b/spec/bundler/bundler/dsl_spec.rb
index 40739a431b..9299c014af 100644
--- a/spec/bundler/bundler/dsl_spec.rb
+++ b/spec/bundler/bundler/dsl_spec.rb
@@ -72,7 +72,7 @@ RSpec.describe Bundler::Dsl do
describe "#method_missing" do
it "raises an error for unknown DSL methods" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).
and_return("unknown")
error_msg = "There was an error parsing `Gemfile`: Undefined local variable or method `unknown' for Gemfile. Bundler cannot continue."
@@ -83,13 +83,13 @@ RSpec.describe Bundler::Dsl do
describe "#eval_gemfile" do
it "handles syntax errors with a useful message" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return("}")
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return("}")
expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: (syntax error, unexpected tSTRING_DEND|(compile error - )?syntax error, unexpected '\}'). Bundler cannot continue./)
end
it "distinguishes syntax errors from evaluation errors" do
- expect(Bundler).to receive(:read_file).with(bundled_app("Gemfile").to_s).and_return(
+ expect(Bundler).to receive(:read_file).with(root.join("Gemfile").to_s).and_return(
"ruby '2.1.5', :engine => 'ruby', :engine_version => '1.2.4'"
)
expect { subject.eval_gemfile("Gemfile") }.
@@ -174,40 +174,6 @@ RSpec.describe Bundler::Dsl do
end
end
- describe "#gemspec" do
- let(:spec) do
- Gem::Specification.new do |gem|
- gem.name = "example"
- gem.platform = platform
- end
- end
-
- before do
- allow(Dir).to receive(:[]).and_return(["spec_path"])
- allow(Bundler).to receive(:load_gemspec).with("spec_path").and_return(spec)
- allow(Bundler).to receive(:default_gemfile).and_return(Pathname.new("./Gemfile"))
- end
-
- context "with a ruby platform" do
- let(:platform) { "ruby" }
-
- it "keeps track of the ruby platforms in the dependency" do
- subject.gemspec
- expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::RUBY])
- end
- end
-
- context "with a jruby platform" do
- let(:platform) { "java" }
-
- it "keeps track of the jruby platforms in the dependency" do
- allow(Gem::Platform).to receive(:local).and_return(java)
- subject.gemspec
- expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::JAVA])
- end
- end
- end
-
context "can bundle groups of gems with" do
# git "https://github.com/rails/rails.git" do
# gem "railties"
@@ -270,7 +236,7 @@ RSpec.describe Bundler::Dsl do
describe "syntax errors" do
it "will raise a Bundler::GemfileError" do
gemfile "gem 'foo', :path => /unquoted/string/syntax/error"
- expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }.
+ expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }.
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`:( compile error -)? unknown regexp options - trg.+ Bundler cannot continue./)
end
end
@@ -278,7 +244,7 @@ RSpec.describe Bundler::Dsl do
describe "Runtime errors" do
it "will raise a Bundler::GemfileError" do
gemfile "raise RuntimeError, 'foo'"
- expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }.
+ expect { Bundler::Dsl.evaluate(bundled_app_gemfile, nil, true) }.
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: foo. Bundler cannot continue./i)
end
end
diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb
index 9631a109bd..fb593639bd 100644
--- a/spec/bundler/bundler/env_spec.rb
+++ b/spec/bundler/bundler/env_spec.rb
@@ -34,6 +34,8 @@ RSpec.describe Bundler::Env do
end
it "prints user home" do
+ skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0"
+
with_clear_paths("HOME", "/a/b/c") do
out = described_class.report
expect(out).to include("User Home /a/b/c")
@@ -41,15 +43,13 @@ RSpec.describe Bundler::Env do
end
it "prints user path" do
- if Gem::VERSION >= "3.2.0.pre.1"
- allow(Gem).to receive(:data_home) { "/a/b/c/.local/share" }
+ skip "needs to use a valid HOME" if Gem.win_platform? && RUBY_VERSION < "2.6.0"
+
+ with_clear_paths("HOME", "/a/b/c") do
+ allow(File).to receive(:exist?)
+ allow(File).to receive(:exist?).with("/a/b/c/.gem").and_return(true)
out = described_class.report
- expect(out).to include("User Path /a/b/c/.local/share/gem")
- else
- with_clear_paths("HOME", "/a/b/c") do
- out = described_class.report
- expect(out).to include("User Path /a/b/c/.gem")
- end
+ expect(out).to include("User Path /a/b/c/.gem")
end
end
@@ -88,6 +88,8 @@ RSpec.describe Bundler::Env do
BUNDLED WITH
1.10.0
L
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
let(:output) { described_class.report(:print_gemfile => true) }
@@ -127,6 +129,8 @@ RSpec.describe Bundler::Env do
File.open(bundled_app.join("foo.gemspec"), "wb") do |f|
f.write(gemspec)
end
+
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "prints the gemspec" do
@@ -139,13 +143,15 @@ RSpec.describe Bundler::Env do
context "when eval_gemfile is used" do
it "prints all gemfiles" do
- create_file "other/Gemfile-other", "gem 'rack'"
- create_file "other/Gemfile", "eval_gemfile 'Gemfile-other'"
- create_file "Gemfile-alt", <<-G
+ create_file bundled_app("other/Gemfile-other"), "gem 'rack'"
+ create_file bundled_app("other/Gemfile"), "eval_gemfile 'Gemfile-other'"
+ create_file bundled_app("Gemfile-alt"), <<-G
source "#{file_uri_for(gem_repo1)}"
eval_gemfile "other/Gemfile"
G
- gemfile "eval_gemfile #{File.expand_path("Gemfile-alt").dump}"
+ gemfile "eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}"
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+ allow(Bundler::SharedHelpers).to receive(:pwd).and_return(bundled_app)
output = described_class.report(:print_gemspecs => true)
expect(output).to include(strip_whitespace(<<-ENV))
@@ -154,7 +160,7 @@ RSpec.describe Bundler::Env do
### Gemfile
```ruby
- eval_gemfile #{File.expand_path("Gemfile-alt").dump}
+ eval_gemfile #{bundled_app("Gemfile-alt").to_s.dump}
```
### Gemfile-alt
@@ -179,7 +185,7 @@ RSpec.describe Bundler::Env do
### Gemfile.lock
```
- <No #{bundled_app("Gemfile.lock")} found>
+ <No #{bundled_app_lock} found>
```
ENV
end
diff --git a/spec/bundler/bundler/fetcher/compact_index_spec.rb b/spec/bundler/bundler/fetcher/compact_index_spec.rb
index c9419d3eb1..b00eadceab 100644
--- a/spec/bundler/bundler/fetcher/compact_index_spec.rb
+++ b/spec/bundler/bundler/fetcher/compact_index_spec.rb
@@ -1,5 +1,8 @@
# frozen_string_literal: true
+# load CompactIndexClient upfront to prevent thread safety issues during parallel specs
+require "bundler/compact_index_client"
+
RSpec.describe Bundler::Fetcher::CompactIndex do
let(:downloader) { double(:downloader) }
let(:display_uri) { Bundler::URI("http://sampleuri.com") }
diff --git a/spec/bundler/bundler/fetcher_spec.rb b/spec/bundler/bundler/fetcher_spec.rb
index 539179db43..256d342775 100644
--- a/spec/bundler/bundler/fetcher_spec.rb
+++ b/spec/bundler/bundler/fetcher_spec.rb
@@ -150,9 +150,10 @@ RSpec.describe Bundler::Fetcher do
end
it "from many CI" do
- with_env_vars("TRAVIS" => "foo", "CI_NAME" => "my_ci") do
+ with_env_vars("TRAVIS" => "foo", "GITLAB_CI" => "gitlab", "CI_NAME" => "my_ci") do
ci_part = fetcher.user_agent.split(" ").find {|x| x.start_with?("ci/") }
expect(ci_part).to match("travis")
+ expect(ci_part).to match("gitlab")
expect(ci_part).to match("my_ci")
end
end
diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb
index dc9d539a30..747d774b25 100644
--- a/spec/bundler/bundler/friendly_errors_spec.rb
+++ b/spec/bundler/bundler/friendly_errors_spec.rb
@@ -6,59 +6,26 @@ require "cgi"
RSpec.describe Bundler, "friendly errors" do
context "with invalid YAML in .gemrc" do
- context "with the old ~/.gemrc" do
- before do
- File.open(home(".gemrc"), "w") do |f|
- f.write "invalid: yaml: hah"
- end
- end
-
- after do
- FileUtils.rm(home(".gemrc"))
- end
-
- it "reports a relevant friendly error message" do
- gemfile <<-G
- source "#{file_uri_for(gem_repo1)}"
- gem "rack"
- G
-
- bundle :install, :env => { "DEBUG" => "true" }
-
- expect(err).to include("Failed to load #{home(".gemrc")}")
- expect(exitstatus).to eq(0) if exitstatus
+ before do
+ File.open(home(".gemrc"), "w") do |f|
+ f.write "invalid: yaml: hah"
end
end
- context "with XDG_CONFIG_HOME" do
- let(:config_home) { File.dirname(Gem.configuration.config_file_name) }
-
- before do
- FileUtils.mkdir_p config_home
- File.open(Gem.configuration.config_file_name, "w") do |f|
- f.write "invalid: yaml: hah"
- end
- end
-
- after do
- FileUtils.rm(Gem.configuration.config_file_name)
- end
+ after do
+ FileUtils.rm(home(".gemrc"))
+ end
- it "reports a relevant friendly error message" do
- gemfile <<-G
- source "#{file_uri_for(gem_repo1)}"
- gem "rack"
- G
+ it "reports a relevant friendly error message" do
+ gemfile <<-G
+ source "#{file_uri_for(gem_repo1)}"
+ gem "rack"
+ G
- bundle :install, :env => { "DEBUG" => "true" }
+ bundle :install, :env => { "DEBUG" => "true" }
- if Gem::VERSION >= "3.2.0.pre.1"
- expect(err).to include("Failed to load #{File.join(config_home, "gemrc")}")
- else
- expect(err).to include("Failed to load #{home(".gemrc")}")
- end
- expect(exitstatus).to eq(0) if exitstatus
- end
+ expect(err).to include("Failed to load #{home(".gemrc")}")
+ expect(exitstatus).to eq(0) if exitstatus
end
end
@@ -148,18 +115,12 @@ RSpec.describe Bundler, "friendly errors" do
context "LoadError" do
let(:error) { LoadError.new("cannot load such file -- openssl") }
- it "Bundler.ui receive error" do
- expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL.")
- Bundler::FriendlyErrors.log_error(error)
- end
-
- it "Bundler.ui receive warn" do
- expect(Bundler.ui).to receive(:warn).with(any_args, :wrap => true)
- Bundler::FriendlyErrors.log_error(error)
+ before do
+ allow(error).to receive(:backtrace).and_return(["backtrace"])
end
- it "Bundler.ui receive trace" do
- expect(Bundler.ui).to receive(:trace).with(error)
+ it "Bundler.ui receive error" do
+ expect(Bundler.ui).to receive(:error).with("\nCould not load OpenSSL. LoadError: cannot load such file -- openssl\nbacktrace")
Bundler::FriendlyErrors.log_error(error)
end
end
@@ -254,7 +215,7 @@ RSpec.describe Bundler, "friendly errors" do
it "generates a search URL for the exception message" do
exception = Exception.new("Exception message")
- expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=Exception+message&type=Issues")
+ expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=Exception+message&type=Issues")
end
it "generates a search URL for only the first line of a multi-line exception message" do
@@ -263,7 +224,7 @@ First line of the exception message
Second line of the exception message
END
- expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/bundler/bundler/search?q=First+line+of+the+exception+message&type=Issues")
+ expect(Bundler::FriendlyErrors.issues_url(exception)).to eq("https://github.com/rubygems/bundler/search?q=First+line+of+the+exception+message&type=Issues")
end
it "generates the url without colons" do
@@ -272,7 +233,7 @@ Exception ::: with ::: colons :::
END
issues_url = Bundler::FriendlyErrors.issues_url(exception)
expect(issues_url).not_to include("%3A")
- expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues")
+ expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Exception with colons ")}&type=Issues")
end
it "removes information after - for Errono::EACCES" do
@@ -282,7 +243,7 @@ END
allow(exception).to receive(:is_a?).with(Errno).and_return(true)
issues_url = Bundler::FriendlyErrors.issues_url(exception)
expect(issues_url).not_to include("/Users/foo/bar")
- expect(issues_url).to eq("https://github.com/bundler/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues")
+ expect(issues_url).to eq("https://github.com/rubygems/bundler/search?q=#{CGI.escape("Errno EACCES Permission denied @ dir_s_mkdir ")}&type=Issues")
end
end
end
diff --git a/spec/bundler/bundler/gem_helper_spec.rb b/spec/bundler/bundler/gem_helper_spec.rb
index 29e10d64f8..548425b11e 100644
--- a/spec/bundler/bundler/gem_helper_spec.rb
+++ b/spec/bundler/bundler/gem_helper_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Bundler::GemHelper do
let(:app_gemspec_path) { app_path.join("#{app_name}.gemspec") }
before(:each) do
- global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false"
+ global_config "BUNDLE_GEM__MIT" => "false", "BUNDLE_GEM__TEST" => "false", "BUNDLE_GEM__COC" => "false", "BUNDLE_GEM__RUBOCOP" => "false"
bundle "gem #{app_name}"
prepare_gemspec(app_gemspec_path)
end
@@ -138,6 +138,26 @@ RSpec.describe Bundler::GemHelper do
expect(app_gem_path).to exist
end
end
+
+ context "when building in the current working directory" do
+ it "creates .gem file" do
+ mock_build_message app_name, app_version
+ Dir.chdir app_path do
+ Bundler::GemHelper.new.build_gem
+ end
+ expect(app_gem_path).to exist
+ end
+ end
+
+ context "when building in a location relative to the current working directory" do
+ it "creates .gem file" do
+ mock_build_message app_name, app_version
+ Dir.chdir File.dirname(app_path) do
+ Bundler::GemHelper.new(File.basename(app_path)).build_gem
+ end
+ expect(app_gem_path).to exist
+ end
+ end
end
describe "#install_gem" do
@@ -178,13 +198,11 @@ RSpec.describe Bundler::GemHelper do
end
before do
- Dir.chdir(app_path) do
- `git init`
- `git config user.email "you@example.com"`
- `git config user.name "name"`
- `git config commit.gpgsign false`
- `git config push.default simple`
- end
+ sys_exec("git init", :dir => app_path)
+ sys_exec("git config user.email \"you@example.com\"", :dir => app_path)
+ sys_exec("git config user.name \"name\"", :dir => app_path)
+ sys_exec("git config commit.gpgsign false", :dir => app_path)
+ sys_exec("git config push.default simple", :dir => app_path)
# silence messages
allow(Bundler.ui).to receive(:confirm)
@@ -198,13 +216,13 @@ RSpec.describe Bundler::GemHelper do
end
it "when there are uncommitted files" do
- Dir.chdir(app_path) { `git add .` }
+ sys_exec("git add .", :dir => app_path)
expect { Rake.application["release"].invoke }.
to raise_error("There are files that need to be committed first.")
end
it "when there is no git remote" do
- Dir.chdir(app_path) { `git commit -a -m "initial commit"` }
+ sys_exec("git commit -a -m \"initial commit\"", :dir => app_path)
expect { Rake.application["release"].invoke }.to raise_error(RuntimeError)
end
end
@@ -213,10 +231,8 @@ RSpec.describe Bundler::GemHelper do
let(:repo) { build_git("foo", :bare => true) }
before do
- Dir.chdir(app_path) do
- sys_exec("git remote add origin #{file_uri_for(repo.path)}")
- sys_exec('git commit -a -m "initial commit"')
- end
+ sys_exec("git remote add origin #{file_uri_for(repo.path)}", :dir => app_path)
+ sys_exec('git commit -a -m "initial commit"', :dir => app_path)
end
context "on releasing" do
@@ -225,7 +241,7 @@ RSpec.describe Bundler::GemHelper do
mock_confirm_message "Tagged v#{app_version}."
mock_confirm_message "Pushed git commits and tags."
- Dir.chdir(app_path) { sys_exec("git push -u origin master") }
+ sys_exec("git push -u origin master", :dir => app_path)
end
it "calls rubygem_push with proper arguments" do
@@ -235,7 +251,8 @@ RSpec.describe Bundler::GemHelper do
end
it "uses Kernel.system" do
- expect(Kernel).to receive(:system).with(gem_bin, "push", app_gem_path.to_s, "--host", "http://example.org").and_return(true)
+ cmd = gem_bin.shellsplit
+ expect(Kernel).to receive(:system).with(*cmd, "push", app_gem_path.to_s, "--host", "http://example.org").and_return(true)
Rake.application["release"].invoke
end
@@ -246,9 +263,7 @@ RSpec.describe Bundler::GemHelper do
mock_confirm_message "Tag v#{app_version} has already been created."
expect(subject).to receive(:rubygem_push).with(app_gem_path.to_s)
- Dir.chdir(app_path) do
- `git tag -a -m \"Version #{app_version}\" v#{app_version}`
- end
+ sys_exec("git tag -a -m \"Version #{app_version}\" v#{app_version}", :dir => app_path)
Rake.application["release"].invoke
end
@@ -269,12 +284,10 @@ RSpec.describe Bundler::GemHelper do
end
before do
- Dir.chdir(app_path) do
- `git init`
- `git config user.email "you@example.com"`
- `git config user.name "name"`
- `git config push.default simple`
- end
+ sys_exec("git init", :dir => app_path)
+ sys_exec("git config user.email \"you@example.com\"", :dir => app_path)
+ sys_exec("git config user.name \"name\"", :dir => app_path)
+ sys_exec("git config push.gpgsign simple", :dir => app_path)
# silence messages
allow(Bundler.ui).to receive(:confirm)
diff --git a/spec/bundler/bundler/mirror_spec.rb b/spec/bundler/bundler/mirror_spec.rb
index 4a8a0c7c48..1eaf1e9a8e 100644
--- a/spec/bundler/bundler/mirror_spec.rb
+++ b/spec/bundler/bundler/mirror_spec.rb
@@ -305,6 +305,8 @@ RSpec.describe Bundler::Settings::TCPSocketProbe do
end
it "probes the server correctly" do
+ skip "obscure error" if Gem.win_platform?
+
with_server_and_mirror do |server, mirror|
expect(server.closed?).to be_falsey
expect(probe.replies?(mirror)).to be_truthy
diff --git a/spec/bundler/bundler/plugin/index_spec.rb b/spec/bundler/bundler/plugin/index_spec.rb
index e18e960fb8..925dc558ac 100644
--- a/spec/bundler/bundler/plugin/index_spec.rb
+++ b/spec/bundler/bundler/plugin/index_spec.rb
@@ -4,6 +4,7 @@ RSpec.describe Bundler::Plugin::Index do
Index = Bundler::Plugin::Index
before do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
gemfile ""
path = lib_path(plugin_name)
index.register_plugin("new-plugin", path.to_s, [path.join("lib").to_s], commands, sources, hooks)
@@ -117,11 +118,11 @@ RSpec.describe Bundler::Plugin::Index do
describe "global index" do
before do
- Dir.chdir(tmp) do
- Bundler::Plugin.reset!
- path = lib_path("gplugin")
- index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], [])
- end
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil)
+
+ Bundler::Plugin.reset!
+ path = lib_path("gplugin")
+ index.register_plugin("gplugin", path.to_s, [path.join("lib").to_s], [], ["glb_source"], [])
end
it "skips sources" do
diff --git a/spec/bundler/bundler/plugin_spec.rb b/spec/bundler/bundler/plugin_spec.rb
index e0e2e9afdf..8c95723bcc 100644
--- a/spec/bundler/bundler/plugin_spec.rb
+++ b/spec/bundler/bundler/plugin_spec.rb
@@ -107,7 +107,7 @@ RSpec.describe Bundler::Plugin do
describe "evaluate gemfile for plugins" do
let(:definition) { double("definition") }
let(:builder) { double("builder") }
- let(:gemfile) { bundled_app("Gemfile") }
+ let(:gemfile) { bundled_app_gemfile }
before do
allow(Plugin::DSL).to receive(:new) { builder }
@@ -237,7 +237,7 @@ RSpec.describe Bundler::Plugin do
describe "#root" do
context "in app dir" do
before do
- gemfile ""
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
end
it "returns plugin dir in app .bundle path" do
@@ -246,8 +246,11 @@ RSpec.describe Bundler::Plugin do
end
context "outside app dir" do
+ before do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(nil)
+ end
+
it "returns plugin dir in global bundle path" do
- Dir.chdir tmp
expect(subject.root).to eq(home.join(".bundle/plugin"))
end
end
diff --git a/spec/bundler/bundler/settings_spec.rb b/spec/bundler/bundler/settings_spec.rb
index b83d768477..116a038445 100644
--- a/spec/bundler/bundler/settings_spec.rb
+++ b/spec/bundler/bundler/settings_spec.rb
@@ -130,6 +130,8 @@ that would suck --ehhh=oh geez it looks like i might have broken bundler somehow
describe "#temporary" do
it "reset after used" do
+ allow(Bundler::SharedHelpers).to receive(:find_gemfile).and_return(bundled_app_gemfile)
+
Bundler.settings.set_command_option :no_install, true
Bundler.settings.temporary(:no_install => false) do
diff --git a/spec/bundler/bundler/shared_helpers_spec.rb b/spec/bundler/bundler/shared_helpers_spec.rb
index 4530a9a5cd..73adcf44d6 100644
--- a/spec/bundler/bundler/shared_helpers_spec.rb
+++ b/spec/bundler/bundler/shared_helpers_spec.rb
@@ -4,10 +4,13 @@ RSpec.describe Bundler::SharedHelpers do
let(:ext_lock_double) { double(:ext_lock) }
before do
+ pwd_stub
allow(Bundler.rubygems).to receive(:ext_lock).and_return(ext_lock_double)
allow(ext_lock_double).to receive(:synchronize) {|&block| block.call }
end
+ let(:pwd_stub) { allow(subject).to receive(:pwd).and_return(bundled_app) }
+
subject { Bundler::SharedHelpers }
describe "#default_gemfile" do
@@ -77,7 +80,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:global_rubygems_dir) { Pathname.new(bundled_app) }
before do
- Dir.mkdir ".bundle"
+ Dir.mkdir bundled_app(".bundle")
allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir)
end
@@ -91,7 +94,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:expected_bundle_dir_path) { Pathname.new("#{bundled_app}/.bundle") }
before do
- Dir.mkdir ".bundle"
+ Dir.mkdir bundled_app(".bundle")
allow(Bundler.rubygems).to receive(:user_home).and_return(global_rubygems_dir)
end
@@ -109,7 +112,8 @@ RSpec.describe Bundler::SharedHelpers do
shared_examples_for "correctly determines whether to return a Gemfile path" do
context "currently in directory with a Gemfile" do
- before { File.new("Gemfile", "w") }
+ before { FileUtils.touch(bundled_app_gemfile) }
+ after { FileUtils.rm(bundled_app_gemfile) }
it "returns path of the bundle Gemfile" do
expect(subject.in_bundle?).to eq("#{bundled_app}/Gemfile")
@@ -147,22 +151,24 @@ RSpec.describe Bundler::SharedHelpers do
describe "#chdir" do
let(:op_block) { proc { Dir.mkdir "nested_dir" } }
- before { Dir.mkdir "chdir_test_dir" }
+ before { Dir.mkdir bundled_app("chdir_test_dir") }
it "executes the passed block while in the specified directory" do
- subject.chdir("chdir_test_dir", &op_block)
- expect(Pathname.new("chdir_test_dir/nested_dir")).to exist
+ subject.chdir(bundled_app("chdir_test_dir"), &op_block)
+ expect(bundled_app("chdir_test_dir/nested_dir")).to exist
end
end
describe "#pwd" do
+ let(:pwd_stub) { nil }
+
it "returns the current absolute path" do
- expect(subject.pwd).to eq(bundled_app)
+ expect(subject.pwd).to eq(root)
end
end
describe "#with_clean_git_env" do
- let(:with_clean_git_env_block) { proc { Dir.mkdir "with_clean_git_env_test_dir" } }
+ let(:with_clean_git_env_block) { proc { Dir.mkdir bundled_app("with_clean_git_env_test_dir") } }
before do
ENV["GIT_DIR"] = "ORIGINAL_ENV_GIT_DIR"
@@ -171,20 +177,20 @@ RSpec.describe Bundler::SharedHelpers do
it "executes the passed block" do
subject.with_clean_git_env(&with_clean_git_env_block)
- expect(Pathname.new("with_clean_git_env_test_dir")).to exist
+ expect(bundled_app("with_clean_git_env_test_dir")).to exist
end
context "when a block is passed" do
let(:with_clean_git_env_block) do
proc do
- Dir.mkdir "git_dir_test_dir" unless ENV["GIT_DIR"].nil?
- Dir.mkdir "git_work_tree_test_dir" unless ENV["GIT_WORK_TREE"].nil?
+ Dir.mkdir bundled_app("git_dir_test_dir") unless ENV["GIT_DIR"].nil?
+ Dir.mkdir bundled_app("git_work_tree_test_dir") unless ENV["GIT_WORK_TREE"].nil?
end end
it "uses a fresh git env for execution" do
subject.with_clean_git_env(&with_clean_git_env_block)
- expect(Pathname.new("git_dir_test_dir")).to_not exist
- expect(Pathname.new("git_work_tree_test_dir")).to_not exist
+ expect(bundled_app("git_dir_test_dir")).to_not exist
+ expect(bundled_app("git_work_tree_test_dir")).to_not exist
end
end
@@ -224,7 +230,7 @@ RSpec.describe Bundler::SharedHelpers do
end
shared_examples_for "ENV['PATH'] gets set correctly" do
- before { Dir.mkdir ".bundle" }
+ before { Dir.mkdir bundled_app(".bundle") }
it "ensures bundle bin path is in ENV['PATH']" do
subject.set_bundle_environment
@@ -244,7 +250,7 @@ RSpec.describe Bundler::SharedHelpers do
let(:ruby_lib_path) { "stubbed_ruby_lib_dir" }
before do
- allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(ruby_lib_path)
+ allow(subject).to receive(:bundler_ruby_lib).and_return(ruby_lib_path)
end
it "ensures bundler's ruby version lib path is in ENV['RUBYLIB']" do
@@ -263,7 +269,7 @@ RSpec.describe Bundler::SharedHelpers do
end
it "ignores if bundler_ruby_lib is same as rubylibdir" do
- allow(Bundler::SharedHelpers).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"])
+ allow(subject).to receive(:bundler_ruby_lib).and_return(RbConfig::CONFIG["rubylibdir"])
subject.set_bundle_environment
@@ -422,8 +428,8 @@ RSpec.describe Bundler::SharedHelpers do
let(:file_op_block) { proc {|path| FileUtils.mkdir_p(path) } }
it "performs the operation in the passed block" do
- subject.filesystem_access("./test_dir", &file_op_block)
- expect(Pathname.new("test_dir")).to exist
+ subject.filesystem_access(bundled_app("test_dir"), &file_op_block)
+ expect(bundled_app("test_dir")).to exist
end
end
diff --git a/spec/bundler/bundler/source/git/git_proxy_spec.rb b/spec/bundler/bundler/source/git/git_proxy_spec.rb
index c18490233d..169d7234b4 100644
--- a/spec/bundler/bundler/source/git/git_proxy_spec.rb
+++ b/spec/bundler/bundler/source/git/git_proxy_spec.rb
@@ -123,6 +123,7 @@ RSpec.describe Bundler::Source::Git::GitProxy do
end
describe "#copy_to" do
+ let(:cache) { tmpdir("cache_path") }
let(:destination) { tmpdir("copy_to_path") }
let(:submodules) { false }
@@ -132,8 +133,8 @@ RSpec.describe Bundler::Source::Git::GitProxy do
it "fails gracefully when resetting to the revision fails" do
expect(subject).to receive(:git_retry).with(start_with("clone ")) { destination.mkpath }
- expect(subject).to receive(:git_retry).with(start_with("fetch "))
- expect(subject).to receive(:git).with(command).and_raise(Bundler::Source::Git::GitCommandError, command)
+ expect(subject).to receive(:git_retry).with(start_with("fetch "), :dir => destination)
+ expect(subject).to receive(:git).with(command, :dir => destination).and_raise(Bundler::Source::Git::GitCommandError.new(command, cache, destination))
expect(subject).not_to receive(:git)
expect { subject.copy_to(destination, submodules) }.