[英]How can I run tests on a pre-populated database in Rails?
So I am writing acceptance tests for a single feature of a large App. 因此,我正在为大型应用程序的单个功能编写验收测试。 I needed a lot of data for this and have a lot of scenarios to test;
为此,我需要大量数据,并且需要测试许多场景。 so I have pre-populated a mysql database using Sequel Pro.
因此,我已经使用Sequel Pro预填充了mysql数据库。
Obviously the appname_test database is in place for the other tests in the app. 显然,应用程序中的其他测试已使用appname_test数据库。 I would like to know how I could load up a .sql file (which is a sql dump of content) into this database at the start of my tests (before the first context statement).
我想知道如何在测试开始时(在第一个context语句之前)将.sql文件(这是内容的sql转储)加载到此数据库中。
I am new to development so this is completely new to me. 我是开发的新手,所以这对我来说是全新的。 Thanks in advance for any help.
在此先感谢您的帮助。
Update: 更新:
I have used the yaml_db gem to dump the dev db ( db:data:dump
) and then load it into the test db ( db:data:load ENV_RAILS=test
). 我已经使用yaml_db gem来转储dev db(
db:data:dump
),然后将其加载到测试db( db:data:load ENV_RAILS=test
)。 However, as soon as I run my specs the test db is wiped clean! 但是,一旦我运行我的规格,测试数据库就会被清除干净! Is there a way to run
db:data:load ENV_RAILS=test
from inside the spec file. 有没有一种方法可以从规范文件中运行
db:data:load ENV_RAILS=test
。 I have tried: 我努力了:
require 'rake'
Rake::Task['bundle exec db:data:load ENV_RAILS=test'].invoke
but it says Don't know how to build task 'be db:data:load ENV_RAILS=test'
但它说不
Don't know how to build task 'be db:data:load ENV_RAILS=test'
OK, so here is what I did to solve this. 好的,这就是我要解决的问题。
I used the yaml_db gem and rake db:data:dump
which creates db/data.yml (a dump of the dev db). 我使用了yaml_db gem和
rake db:data:dump
来创建db / data.yml(开发db的转储)。
I then had to write a library and rake task which converted the data.yml file into individual fixtures files. 然后,我不得不编写一个库和rake任务,将data.yml文件转换为单独的夹具文件。 I run this new rake task once to create the fixure files.
我运行此新的rake任务一次以创建固定文件。
Then, at the start of my spec I call fixtures :all
which populates the test database with all the fixtures. 然后,在我的规范开始时,我称为
fixtures :all
,它使用所有的fixtures填充测试数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.