@@ -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