【问题标题】:Test Unit error when running rake tasks运行 rake 任务时测试单元错误
【发布时间】:2013-12-26 14:32:40
【问题描述】:

我将我的应用程序从 rails2 升级到 rails3。现在每次我运行一个任务我都会得到这个错误:

➜  cimm git:(master) ✗ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin13.0.0]
➜  cimm git:(master) ✗ rails -v
Rails 3.0.20
➜  cimm git:(master) ✗ bundle exec rake sitemaps:servicos --trace
** Invoke sitemaps:servicos (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sitemaps:servicos
/Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: sitemaps:servicos (ArgumentError)
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:21:in `run'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
    from /Users/netto/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

如果我使用 Rspec,我不知道为什么要加载有关测试单元的内容。我尝试更改 rake 版本,更改 require 'rails/all' 但没有解决此问题。

但我的任务已加载,所以这似乎是一种警告。但我想知道如何解决这个问题。

更新 1

这些错误仅在我的任务与模型/控制器交互时出现。

我的 Rakefile:

require File.expand_path('../config/application', __FILE__)
require 'rake'

CIMM::Application.load_tasks

【问题讨论】:

  • rake -T 的输出是什么?
  • @LeoCorrea 看看我下面的评论。
  • 我想一个更好的问题是你在哪里定义任务站点地图:servicos
  • lib/tasks/sitemap.rake 正如我所说.. 任务运行,所以它可以与文件的位置。问题在于测试单元的警告。
  • Gemfile 中有 gem "test-unit",但当前包中没有?

标签: ruby-on-rails ruby ruby-on-rails-3 rake


【解决方案1】:

检查您的 Rakefile。它可能正在加载 TestUnit

如果您需要更多帮助,您应该显示自定义任务。

【讨论】:

  • 看看我的 Rakefile。
【解决方案2】:
➜  cimm git:(master) ✗ rake -T
rake about                                    # List versions of all Rails frameworks and the environment
rake airbrake:deploy                          # Notify Airbrake of a new deploy.
rake airbrake:heroku:add_deploy_notification  # Install Heroku deploy notifications addon
rake airbrake:test                            # Verify your gem installation by sending a test exception to the airbrake service / Verify your gem instal...
rake db:create                                # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all d...
rake db:drop                                  # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load                         # Load fixtures into the current environment's database.
rake db:migrate                               # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status                        # Display status of migrations
rake db:rollback                              # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump                           # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load                           # Load a schema.rb file into the database
rake db:seed                                  # Load the seed data from db/seeds.rb
rake db:setup                                 # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db...
rake db:structure:dump                        # Dump the database structure to an SQL file
rake db:version                               # Retrieves the current schema version number
rake doc:app                                  # Generate docs for the app -- also available doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-t...
rake log:clear                                # Truncates all *.log files in log/ to zero bytes
rake middleware                               # Prints out your Rack middleware stack
rake notes                                    # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom                             # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template                           # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update                             # Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)
rake rails:upgrade:backup                     # Backs up your likely modified files so you can run the Rails 3 generator on your app with little risk
rake rails:upgrade:check                      # Runs a battery of checks on your Rails 2.x app and generates a report on required upgrades for Rails 3
rake rails:upgrade:configuration              # Extracts your configuration code so you can create a new config/application.rb
rake rails:upgrade:gems                       # Generates a Gemfile for your Rails 3 app out of your config.gem directives
rake rails:upgrade:routes                     # Create a new, upgraded route file from your current routes.rb
rake routes                                   # Print out all defined routes in match order, with names.
rake secret                                   # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie se...
rake sitemaps:servicos                        # Cria sitemap para servicos
rake spec                                     # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers                         # Run the code examples in spec/controllers
rake stats                                    # Report code statistics (KLOCs, etc) from the application
rake time:zones:all                           # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter,...
rake tire:import                              # Import data from your model using paginate: rake environment tire:import CLASS='MyModel'.
rake tire:index:drop                          # Delete indices passed in the INDEX environment variable; separate multiple indices by comma.
rake tmp:clear                                # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sock...
rake tmp:create                               # Creates tmp directories for sessions, cache, sockets, and pids

【讨论】:

    猜你喜欢
    • 2011-05-06
    • 2018-02-11
    • 2016-08-20
    • 2018-10-17
    • 2011-10-17
    • 2011-06-07
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多