铁路测试箱固定装置未装载

Dea*_*ano 12 unit-testing ruby-on-rails fixtures

Rails似乎没有为单元或功能测试加载任何灯具.我有一个简单的'products.yml'解析并显示正确:

ruby:
  title: Programming Ruby 1.9
  description:
    Ruby is the fastest growing and most exciting dynamic
    language out there. If you need to get working programs
    delivered fast, you should add Ruby to your toolbox.
  price: 49.50
  image_url: ruby.png
Run Code Online (Sandbox Code Playgroud)

我的控制器功能测试开始于:

require 'test_helper'

class ProductsControllerTest < ActionController::TestCase
  fixtures :products

  setup do
    @product = products(:one)    
    @update = {
      :title => 'Lorem Ipsum' ,
      :description => 'Wibbles are fun!' ,
      :image_url => 'lorem.jpg' ,
      :price => 19.95
    }
  end
Run Code Online (Sandbox Code Playgroud)

根据这本书,Rails应该"神奇地"加载灯具(正如我所test_helper.rb拥有的fixtures :all那样.我还添加了明确的灯具载荷(如上所示).是的Rails抱怨:

user @ host ~/Dropbox/Rails/depot > rake test:functionals
(in /Somewhere/Users/user/Dropbox/Rails/depot)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib:test "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/functional/products_controller_test.rb" 
Loaded suite /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
Started
EEEEEEE
Finished in 0.062506 seconds.

  1) Error:
test_should_create_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7

  2) Error:
test_should_destroy_product(ProductsControllerTest):
NoMethodError: undefined method `products' for ProductsControllerTest:Class
    /test/functional/products_controller_test.rb:7
...
Run Code Online (Sandbox Code Playgroud)

我确实遇到过其他Rails测试夹具问题Rails单元测试没有加载夹具,但这会导致插件问题(与加载夹具的顺序有关).

顺便说一下,我正在使用Rail 2.3.5和Ruby 1.8.7在Mac OS X 10.6上进行开发,没有额外的插件(基本安装之外).

关于如何调试的任何指针,为什么 Rails的魔力似乎在这里失败?这是版本问题吗?我可以将代码跟踪到库中并找到答案吗?有这么多"mixin"模块我找不到fixtures方法真正存在的地方.

Dea*_*ano 0

放弃后,我尝试在 Rail 3.0.0beta3 上重新安装/重建。这解决了问题。我只能假设这是某种版本不匹配。