简体   繁体   English

在运行Cucumber功能之前,如何为测试数据库设置种子?

[英]How to seed the test database before to run Cucumber features?

I am using Ruby on Rails 3.2.2, cucumber-rails-1.3.0 and rspec-rails-2.8.1. 我正在使用Ruby on Rails 3.2.2,cucumber-rails-1.3.0和rspec-rails-2.8.1。 Since I have some "system" data stored in the database, and since I would like to test my application that needs that data in order to properly work, I would like to seed the test database before to run Cucumber features . 由于我在数据库中存储了一些“系统”数据,并且由于我想测试需要该数据才能正常工作的应用程序,因此我想在运行Cucumber功能之前为测试数据库添加种子

How can I make that? 我该怎么做? What do you advice about? 您有什么建议?

Thare is also FactoryGirl. Thare还是FactoryGirl。 It can read from any place but generally uses features/factories.rb or features/factories/*.rb 它可以从任何地方读取,但通常使用features / factories.rb或features / factories / *。rb

See RailsCast 275 . 参见RailsCast 275 Ryan uses it with RSpec, but the principles are the same. Ryan将其与RSpec一起使用,但是原理相同。 Note FactoryGirl has had a major revision since then, so all the API has evolved. 注意自那时起,FactoryGirl就进行了重大修订,因此所有API都在不断发展。

Rails has a feature called Fixtures which prepopulates the test database before testing. Rails具有一项称为Fixtures的功能,可以在测试之前预先填充测试数据库。 Fixtures uses YAML to seed a table of the same name with data. Fixtures使用YAML为具有数据的同名表植入种子。

The Ruby on Rails guides have a low down on fixtures that may be beneficial to have a look at. Ruby on Rails指南对固定装置的要求较低,这可能对您有所帮助。

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

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