简体   繁体   English

如何避免rspec删除测试数据库?

[英]How could avoid the rspec drops the test database?

I have some fake data in the test database, but when I run rake spec the script drops and creates the whole database. 我在测试数据库中有一些虚假数据,但是当我运行rake spec时,脚本会删除并创建整个数据库。 How could I avoid that? 我该如何避免呢? or is it something I'm doing wrong? 还是我做错了什么?

EDIT: I just don't want to generate 1.000.000 records from the database every time. 编辑:我只是不想每次都从数据库生成1.000.000记录。 It took so long. 花了很长时间。

What's the problem? 有什么问题? Your test database should only be used by your tests, are you using it for something else? 您的测试数据库应仅由测试使用,您是否将其用于其他用途?

I'm not sure why you're trying to populate a million records. 我不确定您为什么要填充一百万条记录。 You should take a look into FactoryGirl ( http://github.com/thoughtbot/factory_girl ). 您应该看看FactoryGirl( http://github.com/thoughtbot/factory_girl )。 It's a great replacement to fixtures, and will let you setup your test database in a repeatable way. 它是灯具的理想替代品,可让您以可重复的方式设置测试数据库。

Why on earth do you need 1,000,000 records in the test database? 在地球上,为什么在测试数据库中需要1,000,000条记录? Testing environments aren't for performance testing. 测试环境不适用于性能测试。 You should only have as many records as you need to verify that a feature is functioning correctly. 验证功能是否正常运行时,只应具有所需的记录数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM