Hi, Forwarding a message from Kouhei Sutou regarding an issue we found in the Rake that ships with Ruby by default.
The issue stems around his test-unit2 library, where it's loading the wrong test/unit because of $LOAD_PATH handling when it uses the default Rake. He provides an explanation for the problem and has provided a diff near the bottom. There's a workaround, too. I wasn't sure who should get this, so I sent it to both lists hoping someone could chime in. While I think this is a minor issue now, it could be a larger issue down the road if/when more of the stdlib is turned into gems with the same name. Regards, Dan ---------- Forwarded message ---------- From: Kouhei Sutou <[email protected]> Date: Fri, May 11, 2012 at 7:19 AM Subject: [test-unit-users-en:00074] Re: Having problems with startup when combined with Rake To: [email protected] Hi, In <cagspibmdyopjdfgrsmdoprck5l76l82rmmjzc9k0+e2cmjh...@mail.gmail.com> "[test-unit-users-en:00073] Re: Having problems with startup when combined with Rake" on Thu, 10 May 2012 09:16:09 -0600, Daniel Berger <[email protected]> wrote: > I think I figured it out. Somehow it was picking up the old test-unit > library. Once I renamed that old test-unit directory, everything > worked. I'm not sure why it was happening though, since I was > requiring 'test-unit', not 'test/unit'. > > I did not have my RUBYOPT environment variable set, but I didn't think > it was necessary. > > I'm not sure why it would work with 1.8.7 and not 1.9.3, though. I found the problem. :-) First, here are workarounds: 1. Use :diret loader: Rake::TestTask.new('test_foo') do |t| ... t.loader = :direct ... end 2. Use Rake installed by gem: % gem install rake The cause of the problem is rake/testtask.rb prepends the directory where rake.rb is to $LOAD_PATH. The directory is Ruby's default library diretory when you are using bundled rake. > c:\Users\djberge\Repositories\foo>rake test_foo > c:/usr/bin/ruby.exe -w -I"lib" -I"c:/usr/lib/ruby/1.9.1" > "c:/usr/lib/ruby/1.9.1/rake/rake_test_loader.rb" "test/test_foo.rb" In your case, "c:/usr/lib/ruby/1.9.1" is the direcotry. The directory should not be prepended because RubyGems inserts test-unit's library directory after load paths added by -I. In your case: p $LOAD_PATH -> ["lib", "c:/usr/lib/ruby/1.9.1", "#{Gem.path}/gems/test-unit-2.4.9/lib", ...] test/unit (that is a minitest wrapper not test-unit gem!) is in "c:/usr/lib/ruby/1.9.1". So 'require "test/unit"' requires minitest wrapper instead of test-unit gem. This is the reason for the problem. The solution of this problem is rake/testtask.rb doesn't add -I"c:/usr/lib/ruby/1.9.1" if it's not needed. "c:/usr/lib/ruby/1.9.1" is n't needed because the path is in $LOAD_PATH in default. The directory is "#{Gem.path}/gems/rake-X.Y.Z/lib" if you are using Rake installed by gem. In the case, the -I"..." is needed. OK. Here is a patch against the master of Rake: -- diff --git a/lib/rake/testtask.rb b/lib/rake/testtask.rb index 04d3ae4..98b8c61 100644 --- a/lib/rake/testtask.rb +++ b/lib/rake/testtask.rb @@ -157,7 +157,12 @@ module Rake when :testrb "-S testrb #{fix}" when :rake - "-I\"#{rake_lib_dir}\" \"#{rake_loader}\"" + loarder_code = "\"#{rake_loader}\"" + lib_dir_for_loader = rake_lib_dir + if RbConfig::CONFIG["rubylibdir"] != lib_dir_for_loader + loader_code = "-I\"#{lib_dir_for_loader}\" #{loader_code}" + end + loader_code end end -- Could you send the patch to Rake(*)? I don't have time to send it and discuss about the problem... :< (*) https://github.com/jimweirich/rake Thanks, -- kou _______________________________________________ test-unit-users-en mailing list [email protected] http://rubyforge.org/mailman/listinfo/test-unit-users-en _______________________________________________ Rake-devel mailing list [email protected] http://rubyforge.org/mailman/listinfo/rake-devel
