Rails测试中清空数据表/载入空fixtures

使用spec框架测试,其他测试框架雷同

创建spec/test/empty,其中放入空的yml夹具文件

 

Code

以此载入空的students表

 

当然在执行大量测试时也会存在问题,就是需要将使用的空夹具删除,来载入有效夹具进行其他测试

Code
Fixtures.reset_cache
f
= Fixtures.create_fixtures(File.join(RAILS_ROOT,"spec/fixtures/empty"),"teachers")
Teacher.latest_index.should
== ""
f.delete_existing_fixtures
Fixtures.reset_cache

 

posted @ 2008-10-03 12:50  Tachikoma  阅读(530)  评论(0编辑  收藏  举报