Skip to content

Commit 6217216

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Use ENV consistently over CLI flags for specs
ruby/rubygems@dafe50f171
1 parent 0a8ed97 commit 6217216

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

spec/bundler/runtime/env_helpers_spec.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ def run_bundler_script(env, script)
6262
end
6363

6464
it "removes variables that bundler added", :ruby_repo do
65-
# Simulate bundler has not yet been loaded
66-
ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) })
67-
6865
original = ruby('puts ENV.to_a.map {|e| e.join("=") }.sort.join("\n")', artifice: "fail")
6966
create_file("source.rb", <<-RUBY)
7067
puts Bundler.original_env.to_a.map {|e| e.join("=") }.sort.join("\n")

spec/bundler/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def self.ruby=(ruby)
8484

8585
require_relative "support/rubygems_ext"
8686
Spec::Rubygems.test_setup
87+
88+
# Simulate bundler has not yet been loaded
89+
ENV.replace(ENV.to_hash.delete_if {|k, _v| k.start_with?(Bundler::EnvironmentPreserver::BUNDLER_PREFIX) })
90+
8791
ENV["BUNDLER_SPEC_RUN"] = "true"
8892
ENV["BUNDLE_USER_CONFIG"] = ENV["BUNDLE_USER_CACHE"] = ENV["BUNDLE_USER_PLUGIN"] = nil
8993
ENV["BUNDLE_APP_CONFIG"] = nil

spec/bundler/support/helpers.rb

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ def bundle(cmd, options = {}, &block)
7979
custom_load_path = options.delete(:load_path)
8080

8181
load_path = []
82-
load_path << spec_dir
8382
load_path << custom_load_path if custom_load_path
8483

85-
build_ruby_options = { load_path: load_path, requires: requires, env: env }
86-
build_ruby_options.merge!(artifice: options.delete(:artifice)) if options.key?(:artifice) || cmd.start_with?("exec")
84+
build_env_options = { load_path: load_path, requires: requires, env: env }
85+
build_env_options.merge!(artifice: options.delete(:artifice)) if options.key?(:artifice) || cmd.start_with?("exec")
8786

8887
match_source(cmd)
8988

90-
env, ruby_cmd = build_ruby_cmd(build_ruby_options)
89+
env = build_env(build_env_options)
9190

9291
raise_on_error = options.delete(:raise_on_error)
9392

@@ -102,8 +101,8 @@ def bundle(cmd, options = {}, &block)
102101
end
103102
end.join
104103

105-
cmd = "#{ruby_cmd} #{bundle_bin} #{cmd}#{args}"
106-
env["BUNDLER_SPEC_ORIGINAL_CMD"] = "#{ruby_cmd} #{bundle_bin}" if preserve_ruby_flags
104+
cmd = "#{Gem.ruby} #{bundle_bin} #{cmd}#{args}"
105+
env["BUNDLER_SPEC_ORIGINAL_CMD"] = "#{Gem.ruby} #{bundle_bin}" if preserve_ruby_flags
107106
sys_exec(cmd, { env: env, dir: dir, raise_on_error: raise_on_error }, &block)
108107
end
109108

@@ -123,10 +122,10 @@ def bundler(cmd, options = {})
123122
end
124123

125124
def ruby(ruby, options = {})
126-
env, ruby_cmd = build_ruby_cmd({ artifice: nil }.merge(options))
125+
env = build_env({ artifice: nil }.merge(options))
127126
escaped_ruby = ruby.shellescape
128127
options[:env] = env if env
129-
sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options)
128+
sys_exec(%(#{Gem.ruby} -w -e #{escaped_ruby}), options)
130129
end
131130

132131
def load_error_ruby(ruby, name, opts = {})
@@ -139,17 +138,19 @@ def load_error_ruby(ruby, name, opts = {})
139138
R
140139
end
141140

142-
def build_ruby_cmd(options = {})
143-
libs = options.delete(:load_path)
144-
lib_option = libs ? "-I#{libs.join(File::PATH_SEPARATOR)}" : []
145-
141+
def build_env(options = {})
146142
env = options.delete(:env) || {}
143+
libs = options.delete(:load_path) || []
144+
env["RUBYOPT"] = opt_add("-I#{libs.join(File::PATH_SEPARATOR)}", env["RUBYOPT"]) if libs.any?
145+
147146
current_example = RSpec.current_example
148147

149148
main_source = @gemfile_source if defined?(@gemfile_source)
150149
compact_index_main_source = main_source&.start_with?("https://gem.repo", "https://gems.security")
151150

152151
requires = options.delete(:requires) || []
152+
requires << hax
153+
153154
artifice = options.delete(:artifice) do
154155
if current_example && current_example.metadata[:realworld]
155156
"vcr"
@@ -172,11 +173,9 @@ def build_ruby_cmd(options = {})
172173
requires << "#{Path.spec_dir}/support/artifice/#{artifice}.rb"
173174
end
174175

175-
requires << hax
176-
177-
require_option = requires.map {|r| "-r#{r}" }
176+
requires.each {|r| env["RUBYOPT"] = opt_add("-r#{r}", env["RUBYOPT"]) }
178177

179-
[env, [Gem.ruby, *lib_option, *require_option].compact.join(" ")]
178+
env
180179
end
181180

182181
def gembin(cmd, options = {})

0 commit comments

Comments
 (0)