4

这是一个奇怪的问题。我在运行 rake 进行测试时遇到此错误,但在迁移时却没有。我正在运行 RVM,下面的 shell 转储应该提供您需要的任何信息。

任何帮助将不胜感激。我见过其他几个人遇到这个问题,但还没有对我(或他们)有用的解决方案。

谢谢。

$ rake
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Errors running test:units, test:functionals, test:integration!



$ ruby -v
    ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
    $ rails -v
    Rails 3.1.6

$ more .rvmrc 
rvm ruby-1.9.3-p194@...
$ rake db:rollback
==  AddAllLocationsToAlert: reverting =========================================
-- remove_column(...
   -> 0.0320s
==  AddAllLocationsToAlert: reverted (0.0321s) ================================

- - - - 编辑::::

我已经升级到最新的 Rails - 3.2.6。即使我使用'bundle exec',错误仍然存​​在。(这对 3.2.6 来说并不新鲜——我仍然在 3.1 下遇到问题) undefined 方法是新的。

Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ bundle exec rake
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Errors running test:units! #<NoMethodError: undefined method `[]' for nil:NilClass>
Errors running test:functionals! #<RuntimeError: Command failed with status (7): [/Users/ben/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:integration! #<RuntimeError: Command failed with status (7): [/Users/ben/.rvm/rubies/ruby-1.9.3-p194/bin...]>

我的 Gemfile,按要求:

source 'http://rubygems.org'

gem 'rails', '3.2.6'

group :assets do
  gem 'sass-rails', "  ~> 3.2.5"
  gem 'coffee-rails', "~> 3.2.1"
  gem 'uglifier', '>= 1.2.6'
end

gem 'jquery-rails'

gem 'rake'
gem "mysql2"

gem "squeel"
gem 'tinymce-rails'
gem 'dynamic_form'

gem 'will_paginate'
gem 'devise'
gem 'whitelist'
gem 'rmagick'
gem 'json'
gem 'paperclip'
gem 'acts_as_list', :git => 'https://github.com/swanandp/acts_as_list'
gem 'htmlentities'
gem 'formtastic'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end
4

2 回答 2

3

gem 'rake', ">=0.9.2" # 在你的 Gemfile

然后

$捆绑安装

然后

$ bundle exec rake

如果以上不起作用:

$ rvm all do gem install rake -v 0.9.2.2#install rake to all ruby​​ 版本

然后再次运行 rake

于 2013-03-11T10:50:14.613 回答
0

如果您正在使用 bundler(并且使用 rails,您可能会这样做),请始终像这样运行 rake:

bundle exec rake

这将获取您的 Gemfile 中指定的宝石。

于 2012-07-24T10:09:42.890 回答