From d4598ca9395d5757b5987037ae23827347a9385d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 14 Apr 2019 13:22:53 +0200 Subject: Add require so that env specs can run in isolation --- spec/bundler/env_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb index 20bd38b021..45294960dd 100644 --- a/spec/bundler/env_spec.rb +++ b/spec/bundler/env_spec.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "openssl" require "bundler/settings" RSpec.describe Bundler::Env do -- cgit v1.2.1 From 65f63305a295f5ce10710235cbe83359fde65157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 14 Apr 2019 13:23:29 +0200 Subject: Add some specs for rubygems paths in `bundle env` --- spec/bundler/env_spec.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb index 45294960dd..3d42c6df02 100644 --- a/spec/bundler/env_spec.rb +++ b/spec/bundler/env_spec.rb @@ -18,6 +18,47 @@ RSpec.describe Bundler::Env do expect(out).to include(OpenSSL::OPENSSL_VERSION) end + describe "rubygems paths" do + it "prints gem home" do + with_clear_paths("GEM_HOME", "/a/b/c") do + out = described_class.report + expect(out).to include("Gem Home /a/b/c") + end + end + + it "prints gem path" do + with_clear_paths("GEM_PATH", "/a/b/c:/d/e/f") do + out = described_class.report + expect(out).to include("Gem Path /a/b/c:/d/e/f") + end + end + + it "prints user path" do + with_clear_paths("HOME", "/a/b/c") do + out = described_class.report + expect(out).to include("User Path /a/b/c/.gem") + end + end + + it "prints bin dir" do + with_clear_paths("GEM_HOME", "/a/b/c") do + out = described_class.report + expect(out).to include("Bin Dir /a/b/c/bin") + end + end + + private + + def with_clear_paths(env_var, env_value) + old_env_var = ENV[env_var] + ENV[env_var] = env_value + Gem.clear_paths + yield + ensure + ENV[env_var] = old_env_var + end + end + context "when there is a Gemfile and a lockfile and print_gemfile is true" do before do gemfile "gem 'rack', '1.0.0'" -- cgit v1.2.1 From c26781539a3b12385a6905cc428d4001dd668e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 14 Apr 2019 13:23:55 +0200 Subject: Add user home to `bundle env` --- lib/bundler/env.rb | 1 + spec/bundler/env_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 9cd9b8baca..80974b67ce 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -102,6 +102,7 @@ module Bundler out << ["RubyGems", Gem::VERSION] out << [" Gem Home", ENV.fetch("GEM_HOME") { Gem.dir }] out << [" Gem Path", ENV.fetch("GEM_PATH") { Gem.path.join(File::PATH_SEPARATOR) }] + out << [" User Home", Gem.user_home] out << [" User Path", Gem.user_dir] out << [" Bin Dir", Gem.bindir] if defined?(OpenSSL) diff --git a/spec/bundler/env_spec.rb b/spec/bundler/env_spec.rb index 3d42c6df02..8323a9a7b3 100644 --- a/spec/bundler/env_spec.rb +++ b/spec/bundler/env_spec.rb @@ -33,6 +33,13 @@ RSpec.describe Bundler::Env do end end + it "prints user home" do + with_clear_paths("HOME", "/a/b/c") do + out = described_class.report + expect(out).to include("User Home /a/b/c") + end + end + it "prints user path" do with_clear_paths("HOME", "/a/b/c") do out = described_class.report -- cgit v1.2.1 From d0fe3a054234f407ebd6b1ff9a35bf30ae67f020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 14 Apr 2019 13:53:54 +0200 Subject: Remove unnecessary env variable checking Rubygems already sets these paths from the environment, and once they are set, it uses the paths and not the environment. So the check is unnecessary and potentially misleading. --- lib/bundler/env.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 80974b67ce..3216eb2776 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -100,8 +100,8 @@ module Bundler out << [" Full Path", Gem.ruby] out << [" Config Dir", Pathname.new(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE).dirname] out << ["RubyGems", Gem::VERSION] - out << [" Gem Home", ENV.fetch("GEM_HOME") { Gem.dir }] - out << [" Gem Path", ENV.fetch("GEM_PATH") { Gem.path.join(File::PATH_SEPARATOR) }] + out << [" Gem Home", Gem.dir] + out << [" Gem Path", Gem.path.join(File::PATH_SEPARATOR)] out << [" User Home", Gem.user_home] out << [" User Path", Gem.user_dir] out << [" Bin Dir", Gem.bindir] -- cgit v1.2.1