軌道似乎不是被加載任何裝置進行單元或功能測試。我有一個簡單的「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,但這會導致插件問題(與加載夾具的順序有關)。
順便說一句,我正在開發Mac OS X 10.6 Rail 2.3.5和Ruby 1.8.7,沒有額外的插件(超出基本安裝)。
任何關於如何調試的指針,爲什麼 Rails的魔法似乎在這裏失敗?這是版本問題嗎?我可以將代碼追蹤到庫中並找到答案嗎?有很多「mixin」模塊,我找不到fixtures
方法真正存在的地方。
當您需要查找方法文檔時,APIdock對於此類時間很有用。 http://apidock.com/rails/ActiveRecord/TestFixtures/ClassMethods/fixtures – x1a4 2010-06-06 17:44:14
謝謝x1a4! apidocks是一個非常方便的工具,我將添加到我的工具箱中。仍然不確定究其根本原因是什麼... – Deano 2010-06-06 19:32:17