2010年8月24日火曜日

Railsのテストで Fixtureで作ったデータを簡単に呼び出す方法

Class: Fixtures
Alternatively, you may enable auto-instantiation of the fixture data. For instance, take the following tests:

test "find_alt_method_1" do
assert_equal "Ruby on Rails", @web_sites['rubyonrails']['name']
end

test "find_alt_method_2" do
assert_equal "Ruby on Rails", @rubyonrails.news
end

In order to use these methods to access fixtured data within your testcases, you must specify one of the following in your ActiveSupport::TestCase-derived class:

* to fully enable instantiated fixtures (enable alternate methods 1 and 2 above)

self.use_instantiated_fixtures = true

* create only the hash for the fixtures, do not ‘find’ each instance (enable alternate method 1 only)

self.use_instantiated_fixtures = :no_instances

self.use_instantiated_fixturesの設定が必要。データが多いとパフォーマンスに影響があるみたい。

0 件のコメント:

ブログ アーカイブ

カテゴリー