@@ -150,6 +150,12 @@ def specify_consistent_ordering_of_files_to_run(pattern, file_searcher)
150150 describe "load path manipulation" do
151151 def self . it_configures_rspec_load_path ( description , path_template )
152152 context "when rspec is installed as #{ description } " do
153+ # Matchers are lazily loaded via `autoload`, so we need to get the matcher before
154+ # the load path is manipulated, so we're using `let!` here to do that.
155+ let! ( :include_expected_load_path_option ) do
156+ match ( / -I'?#{ path_template % "rspec-core" } '?#{ File ::PATH_SEPARATOR } '?#{ path_template % "rspec-support" } '? / )
157+ end
158+
153159 it "adds the current rspec-core and rspec-support dirs to the load path to ensure the current version is used" do
154160 $LOAD_PATH. replace ( [
155161 path_template % "rspec-core" ,
@@ -159,7 +165,7 @@ def self.it_configures_rspec_load_path(description, path_template)
159165 path_template % "rake"
160166 ] )
161167
162- expect ( spec_command ) . to match ( / -I'? #{ path_template % "rspec-core" } '? #{ File :: PATH_SEPARATOR } '? #{ path_template % "rspec-support" } '? / )
168+ expect ( spec_command ) . to include_expected_load_path_option
163169 end
164170
165171 it "avoids adding the same load path entries twice" do
@@ -170,7 +176,7 @@ def self.it_configures_rspec_load_path(description, path_template)
170176 path_template % "rspec-support"
171177 ] )
172178
173- expect ( spec_command ) . to match ( / -I'? #{ path_template % "rspec-core" } '? #{ File :: PATH_SEPARATOR } '? #{ path_template % "rspec-support" } '? / )
179+ expect ( spec_command ) . to include_expected_load_path_option
174180 end
175181 end
176182 end
@@ -185,22 +191,25 @@ def self.it_configures_rspec_load_path(description, path_template)
185191 "/Users/myron/.gem/ruby/1.9.3/gems/%s-3.1.0.beta1/lib"
186192
187193 it "does not include extra load path entries for other gems that have `rspec-core` in its path" do
194+ # matchers are lazily loaded with autoload, so we need to get the matcher before manipulating the load path.
195+ include_extra_load_path_entries = include ( "simplecov" , "minitest" , "rspec-core/spec" )
196+
188197 # these are items on my load path due to `bundle install --standalone`,
189198 # and my initial logic caused all these to be included in the `-I` option.
190199 $LOAD_PATH. replace ( [
191- "/Users/myron /code/rspec-dev/repos/rspec-core/spec" ,
192- "/Users/myron /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/simplecov-0.8.2/lib" ,
193- "/Users/myron /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/simplecov-html-0.8.0/lib" ,
194- "/Users/myron /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/minitest-5.3.3/lib" ,
195- "/Users/myron /code/rspec-dev/repos/rspec/lib" ,
196- "/Users/myron /code/rspec-dev/repos/rspec-mocks/lib" ,
197- "/Users/myron /code/rspec-dev/repos/rspec-core/lib" ,
198- "/Users/myron /code/rspec-dev/repos/rspec-expectations/lib" ,
199- "/Users/myron /code/rspec-dev/repos/rspec-support/lib" ,
200- "/Users/myron /code/rspec-dev/repos/rspec-core/bundle" ,
200+ "/Users/user /code/rspec-dev/repos/rspec-core/spec" ,
201+ "/Users/user /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/simplecov-0.8.2/lib" ,
202+ "/Users/user /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/simplecov-html-0.8.0/lib" ,
203+ "/Users/user /code/rspec-dev/repos/rspec-core/bundle/ruby/1.9.1/gems/minitest-5.3.3/lib" ,
204+ "/Users/user /code/rspec-dev/repos/rspec/lib" ,
205+ "/Users/user /code/rspec-dev/repos/rspec-mocks/lib" ,
206+ "/Users/user /code/rspec-dev/repos/rspec-core/lib" ,
207+ "/Users/user /code/rspec-dev/repos/rspec-expectations/lib" ,
208+ "/Users/user /code/rspec-dev/repos/rspec-support/lib" ,
209+ "/Users/user /code/rspec-dev/repos/rspec-core/bundle" ,
201210 ] )
202211
203- expect ( spec_command ) . not_to include ( "simplecov" , "minitest" , "rspec-core/spec" )
212+ expect ( spec_command ) . not_to include_extra_load_path_entries
204213 end
205214 end
206215
0 commit comments