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 does not load Fixturesに出くわしましたが、それはプラグインの問題につながります(フィクスチャをロードする順序と関係があります)。
ところで、私は Rail 2.3.5 と Ruby 1.8.7 を使用して Mac OS X 10.6 で開発しています。追加のプラグインはありません (基本インストール以外)。
Railsの魔法がここで失敗しているように見えるのはなぜですか? バージョンの問題ですか?ライブラリのコードをたどって答えを見つけることはできますか? fixtures
メソッドが実際に存在する場所を見つけることができないほど多くの「ミックスイン」モジュールがあります。