1

我正在使用 rails 4.2,我正在尝试使用命令 rake test 运行测试。我正在尝试使用 plv8 扩展,所以我从 psql 控制台手动创建它,然后当我运行测试时,它似乎已经从 postgres 中删除了该扩展. 我查看了 rails 4.2 项目,我注意到他们带来了 test:db: prepare。这就是每次删除 plv8 扩展的原因。如何添加一段将在 test:db:prepare 或 test:db:create 之后运行的代码?

我不是修改 Rakefile 解决方案的忠实粉丝。

4

1 回答 1

1

您可以内联命名多个任务:

rake test:db:create test:db:prepare custom:task

或者,当您创建一个新的 rake 任务时,您可以使其依赖于任何其他任务:

desc "the dependent task will run before this one"
task my_task: :other_task do
   # stuff
end

你也可以任意调用其他任务:

Rake::Task['db:test:prepare'].invoke

更多信息在这里:http: //jasonseifer.com/2010/04/06/rake-tutorial和这里:如何从 Rake 任务中运行 Rake 任务?

于 2014-12-30T18:55:28.537 回答