运行rake任务时测试单元错误

时间:2013-12-26 14:32:41

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

我将我的应用从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'rail / all'但没有修复此问题。

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

更新1

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

我的Rakefile:

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

CIMM::Application.load_tasks

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

➜  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