LearnRubyTheHardWay Ex#46 - rake aborted,你应该要求'minitest / autorun'

时间:2015-08-24 00:07:43

标签: ruby-on-rails ruby powershell ruby-on-rails-4 gem

我在学习Ruby的例子46中艰难的方法 - 创建一个项目骨架

链接:http://learnrubythehardway.org/book/ex46.html

所以我创建了所有显示如下的目录:

skeleton/
    NAME.gemspec
    Rakefile
    data
    ext/
    tests/
    bin/
        NAME
    doc/
    lib/
        NAME
        NAME.rb
    lib/NAME
    tests/
        test_NAME.rb

我在Powershell的Skeleton目录中。

当我按照教程说的那样运行rake test时,我收到错误。

以下是Powershell的结果:

PS C:\ruby\learn\projects\skeleton> rake test
C:/RailsInstaller/Ruby2.1.0/bin/ruby.exe -I"lib;tests" -I"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4
.2/lib" "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "tests/test_NAME
.rb"
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:1:in `<top (required)>'
  C:/ruby/learn/projects/skeleton/tests/test_NAME.rb:2:in `<top (required)>'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:15:in `block in <main>'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `select'
  C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit/testcase.rb:8:
in `<module:Unit>'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:676:in `<class:Runner>': undefined method `_run_suite' for class
 `Test::Unit::Runner' (NameError)
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:261:in `<module:Unit>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:15:in `<module:Test>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/test/unit.rb:7:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/ruby/learn/projects/skeleton/tests/test_NAME.rb:2:in `<top (required)>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:15:in `block
in <main>'
        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `select'

        from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb:4:in `<main>'

rake aborted!
Command failed with status (1): [ruby -I"lib;tests" -I"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/
lib" "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.rb" "tests/test_NAME.rb
" ]

Tasks: TOP => test
(See full trace by running task with --trace)

这本书说我应该得到以下回应:

Loaded suite tests/test_NAME
Started
.
Finished in 0.000226 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

但我得到了一个错误。我正在搜索修复程序并使用gem install minitest,但请记住,我没有gemfile,我不知道是否应该使用这种类型的项目。如果我需要一个,我认为教程会这样说。那么我该怎么做才能解决这个问题呢?

1 个答案:

答案 0 :(得分:3)

您不需要Gemfile。当您在skeleton目录时,只需执行:

gem install 'test-unit'

然后从同一目录:

rake test

所有测试都将通过。

P.S。我只是按照你的教程在本地重现了整个事情并得到了你的错误信息。然后,我安装了test-unit gem,之后rake test正在运行,没有任何错误。