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
我的控制器功能测试开始于:
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
根据这本书,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
...
我确实遇到了其他 Rails 测试夹具问题Rails unit testing doesn't load fixtures,但这会导致插件问题(与加载夹具的顺序有关)。
顺便说一句,我正在使用 Rail 2.3.5 和 Ruby 1.8.7 的 Mac OS X 10.6 上开发,没有额外的插件(除了基本安装)。
关于如何调试的任何指示,为什么Rails 的魔力在这里似乎失败了?是版本问题吗?我可以将代码跟踪到库中并找到答案吗?有这么多“mixin”模块,我找不到该fixtures
方法真正存在的地方。