1

我有一个最新的 rails 应用程序,使用带有 mongoid 2 的 rails 3.2。我无法通过键入 rake 开始测试。抛出的异常是(已清理):

rake test                                                                                                                         
/railsapp/app/models/image.rb:18:in `<class:Image>': undefined method `[]' for nil:NilClass (NoMethodError)
    from /railsapp/app/models/image.rb:1:in `<top (required)>'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:313:in `depend_on'
    from /gems/activesupport-3.2.8/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /gems/railties-3.2.8/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /gems/railties-3.2.8/lib/rails/engine.rb:438:in `each'
    from /gems/railties-3.2.8/lib/rails/engine.rb:438:in `block in eager_load!'
    from /gems/railties-3.2.8/lib/rails/engine.rb:436:in `each'
    from /gems/railties-3.2.8/lib/rails/engine.rb:436:in `eager_load!'
    from /gems/railties-3.2.8/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
    from /gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
    from /gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
    from /gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
    from /gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
    from /gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /railsapp/config/environment.rb:7:in `<top (required)>'
    from /railsapp/test/test_helper.rb:2:in `require'
    from /railsapp/test/test_helper.rb:2:in `<top (required)>'
    from /railsapp/test/unit/post_test.rb:1:in `require'
    from /railsapp/test/unit/post_test.rb:1:in `<top (required)>'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
Errors running test:units! #<RuntimeError: Command failed with status (1): [/Users/janlimpens/.rvm/rubies/ruby-1.9.3-p...]>

我用上下文中感兴趣的文件创建了一个要点: https ://gist.github.com/3989760

根本没有关于图像模型的测试,没有固定装置,我得到的唯一测试包含在要点中,但这不是罪魁祸首,错误是在包含 test_helper.rb 时引发的。

我有哪些选择?

4

1 回答 1

1

当测试开始 Rails 加载时,它会评估所有模型。

这包括 Image 模型,它在第 18 行显然有一个错误或错字。

这将是这一行:

:path => "#{APP_CONFIG['uploads_dir']}/:class/:id/:attachment/:style.:extension",

这里唯一的数组表示法是:

APP_CONFIG['uploads_dir']

那么,APP_CONFIG 是在哪里定义的呢?为什么它是零?这些都是我们必须回答的问题。

您可以从 grepping 您的项目中获取此字符串开始。

于 2012-10-31T21:19:36.853 回答