为什么rake_test_loader.rb在RVM ruby​​版本2.2.1下的Rake中运行测试时失败(LoadError)

时间:2015-04-07 11:23:13

标签: ruby rake rvm

我刚开始使用RVM并安装了ruby 2.2.1版。我有一个测试项目,其Rake测试任务我成功地使用系统版本(2.0.0)执行测试。当我通过RVM切换到2.2.1时,rake_test_loader失败并出现LoadError。

据我所知,以下是可能的罪魁祸首

  1. 正在使用的不同版本的Ruby
  2. RVM环境导致问题
  3. RVM和Rake存在问题
  4. 我的代码被打包成标​​准的gem结构。 rake文件如下:

    ($LOAD_PATH << File.expand_path("../lib", __FILE__)).uniq!
    
    require 'rake/testtask'
    require 'rdoc/task'
    require 'rubygems/package_task'
    
    # Run All Tests Task
    #
    Rake::TestTask.new('test') do |t|
      t.pattern = 'test/**/*tests.rb'
      t.warning = true
    end
    
    task "default" => ["test"]
    

    确切的错误(设置了--trace标志)如下:

      

    /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- test/unit (LoadError) from /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require'from   /Users/Sancho/dev/git/joy/test/expression/core_staging_gallery_name_regexp_tests.rb:1:in   <top (required)>' from /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in需要'来自   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:10:in 块(2级)in'from   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:9:in   each' from /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:9:in 阻止'来自   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in   select' from /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in '耙子中止了!命令失败,状态为(1):[ruby -w   -I“lib”“/ Users / Sancho / .rvm / rubies / ruby​​-2.2.1 / lib / ruby​​ / 2/2/2 / lake / rake_test_loader.rb”   “test / ** / * tests.rb”]   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:108:in   block (3 levels) in define' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:57:in 称之为”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:57:in   sh' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:37:in SH”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils.rb:96:in   ruby' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:37:in 红宝石”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:104:in   block (2 levels) in define' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/file_utils_ext.rb:58:in 冗长”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/testtask.rb:100:in   block in define' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in 称之为”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in   block in execute' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in 每个”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in   invoke_with_call_chain'execute' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in 阻止   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in   mon_synchronize' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in invoke_with_call_chain'   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in   invoke' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in invoke_task”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in   block (2 levels) in top_level' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in 每个”   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in   block in top_level' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in run_with_threads'   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in   top_level' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in 阻止运行'   /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in   standard_exception_handling' /Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in 运行'/Users/Sancho/.rvm/rubies/ruby-2.2.1/bin/rake:33:in`'   任务:TOP =&gt;测试

    我不确定上面的跟踪是否有用,所以当在系统ruby版本2.0.0和RVM ruby​​版本2.2.1下运行测试时,我显示了$ LOAD_PATH

    在RVM ruby​​版本2.2.1下测试失败时,

    $ LOAD_PATH:

    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/x86_64-darwin14",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby/2.2.0",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby/2.2.0/x86_64-darwin14",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/vendor_ruby",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0",
    "/Users/Sancho/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/x86_64-darwin14",
    "/Users/Sancho/dev/git/joy/lib"
    
    测试在2.0.0下传递时

    $ LOAD_PATH:

    "/Library/Ruby/Site/2.0.0",
    "/Library/Ruby/Site/2.0.0/x86_64-darwin13",
    "/Library/Ruby/Site/2.0.0/universal-darwin13",
    "/Library/Ruby/Site",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0/x86_64-darwin13",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby/2.0.0/universal-darwin13",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/vendor_ruby",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/x86_64-darwin13",
    "/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13",
    "/Users/Sancho/dev/git/joy/lib"
    

    项目的根目录是/ Users / Sancho / dev / git / joy /

    测试位于/ Users / Sancho / dev / git / joy / test /.../*_ tests.rb

    测试中的代码位于/ Users / Sancho / dev / git / joy / lib / joy /.../*。rb

    总而言之,在两个场景中都执行相同的代码(由rake测试任务调用),1个传递另一个失败。第一种情况是使用ruby的系统版本(版本2.0.0,通过),第二种情况是RVM ruby​​版本2.2.1(失败)。

    那么,是什么导致了LoadError问题呢?

    感谢。

    更新:

    我已经通过RVM安装了版本2.0.0p598(而不是系统版本2.0.0p481。(我不得不使用p598,因为p481不再可用)。 使用版本2.0.0p598,测试工作正常。这排除了RVM本身就是一个问题,让我相信最新版本的ruby 2.2.1存在问题。任何人都可以对此有所了解吗?

    更新2号: Ruby版本2.1.1p76也可以。

0 个答案:

没有答案