【问题标题】:Rails 'rake test' runs test twice immediately after creating new rails projectRails 'rake test' 在创建新的 rails 项目后立即运行测试两次
【发布时间】:2011-10-07 05:06:39
【问题描述】:

有人可以在这里提供故障排除提示吗?:

使用以下rails相关命令序列:

rails new test6  
bundle install  
rails generate Controller Gohere left right up down
rake test

... 似乎运行了两次 rake 任务“测试”。我哪里出错了?

日志在这里:

perrys-MacBook-Pro:rails_projects perry_mac$ rails new test6
      create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/mailers
      create  app/models
      create  app/views/layouts/application.html.erb
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/production.rb
      create  config/environments/test.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/initializers/session_store.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/favicon.ico
      create  public/index.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/application.js
      create  public/javascripts/controls.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/effects.js
      create  public/javascripts/prototype.js
      create  public/javascripts/rails.js
      create  script
      create  script/rails
      create  test
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/unit
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
perrys-MacBook-Pro:rails_projects perry_mac$ cd test6
perrys-MacBook-Pro:test6 perry_mac$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.9.2) 
Using abstract (1.0.0) 
Using activesupport (3.0.9) 
Using builder (2.1.2) 
Using i18n (0.5.0) 
Using activemodel (3.0.9) 
Using erubis (2.6.6) 
Using rack (1.2.3) 
Using rack-mount (0.6.14) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.29) 
Using actionpack (3.0.9) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.9) 
Using mail (2.2.19) 
Using actionmailer (3.0.9) 
Using arel (2.0.10) 
Using activerecord (3.0.9) 
Using activeresource (3.0.9) 
Using bundler (1.0.15) 
Using rdoc (3.8) 
Using thor (0.14.6) 
Using railties (3.0.9) 
Using rails (3.0.9) 
Using sqlite3 (1.3.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
perrys-MacBook-Pro:test6 perry_mac$ rake test
perrys-MacBook-Pro:test6 perry_mac$ rails generate controller Gohere left right up down
      create  app/controllers/gohere_controller.rb
       route  get "gohere/down"
       route  get "gohere/up"
       route  get "gohere/right"
       route  get "gohere/left"
      invoke  erb
      create    app/views/gohere
      create    app/views/gohere/left.html.erb
      create    app/views/gohere/right.html.erb
      create    app/views/gohere/up.html.erb
      create    app/views/gohere/down.html.erb
      invoke  test_unit
      create    test/functional/gohere_controller_test.rb
      invoke  helper
      create    app/helpers/gohere_helper.rb
      invoke    test_unit
      create      test/unit/helpers/gohere_helper_test.rb
perrys-MacBook-Pro:test6 perry_mac$ rake test                                   Loaded suite /Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started

Finished in 0.002747 seconds.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 15229
Loaded suite /Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
....
Finished in 0.438403 seconds.

4 tests, 4 assertions, 0 failures, 0 errors, 0 skips

Test run options: --seed 9266
perrys-MacBook-Pro:test6 perry_mac$ 

... 和 rvm 信息产生:

perrys-MacBook-Pro:test6 perry_mac$ rvm info

ruby-1.9.2-p290:

  system:
    uname:       "Darwin perrys-MacBook-Pro.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 i386"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
    zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"

  rvm:
    version:      "rvm 1.6.23 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.2p290"
    date:         "2011-07-09"
    platform:     "x86_64-darwin10.8.0"
    patchlevel:   "2011-07-09 revision 32553"
    full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]"

  homes:
    gem:          "/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290"
    ruby:         "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290"

  binaries:
    ruby:         "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
    irb:          "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
    gem:          "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
    rake:         "/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/bin/rake"

  environment:
    PATH:         "/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290/bin:/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/perry_mac/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin"
    GEM_HOME:     "/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290"
    GEM_PATH:     "/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290:/Users/perry_mac/.rvm/gems/ruby-1.9.2-p290@global"
    MY_RUBY_HOME: "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290"
    IRBRC:        "/Users/perry_mac/.rvm/rubies/ruby-1.9.2-p290/.irbrc"
    RUBYOPT:      ""
    gemset:       ""


perrys-MacBook-Pro:test6 perry_mac$ 

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 unit-testing rspec rake


    【解决方案1】:

    我知道这篇文章已经很老了,但如果你从来没有弄清楚,或者其他人对此感到困惑(就像我今晚一样),这就是发生了什么:

    这里实际上运行了 2 组测试:功能测试和单元测试。当您像这样在一个新的 Rails 项目中生成控制器时,您会得到一些功能测试,并且会得到一个没有实际测试的单元测试文件。

    所以,你看到的第一行测试结果:

    0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
    

    是空单元测试文件的结果。

    只要您填写了一些单元测试,它就会显示非零结果。请注意,您也可以运行 rake test:unitsrake test:functionals 来只运行一组测试。

    我希望有一些更清晰的输出来指示正在发生的事情。它令人困惑的。

    【讨论】:

    • 谢谢亚当。我同意。前一阵子想通了,但懒得在这里更新。 120+ 的浏览量并没有使这个问题成为 SO 上最受欢迎的问题,但我也同意这可能也会让其他人感到困惑。感谢您的回答。我不确定为什么单元测试和功能测试在执行和输出方面是分开处理的。在弄清楚单元和功能测试也以不同的方式处理他们的测试数据之前,我也相当偏离了轨道。基本上,我忽略了 TDD,因为它感觉很麻烦。由于 Ruby 不是一种编译语言,我理解 TDD 的必要性,但它很痛苦。
    • ...阅读我的评论后,我意识到使用 TDD 有很多其他原因,但这并不能减轻痛苦。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多