如何在不删除数据库内容的情况下运行Rails集成测试

如何在不删除数据库内容的情况下运行Rails集成测试

本文介绍了如何在不删除数据库内容的情况下运行Rails集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一些集成测试,这些测试要在推向生产之前在prod数据库的副本上运行.这样一来,我可以测试我所有的路线是否仍然正确,所有页面的呈现都没有错误,并且某些多页面工作流程可以按预期工作.

I've written some integration tests that I'd like to run against a copy of my prod database before I push to production. This lets me test all of my routes are still correct, all of the pages render without errors and some of the multipage workflows work as expected.

当我运行集成测试时,它将删除我已加载的数据库并加载测试装置(如预期的那样).如何更改此行为并保留已加载的生产数据库的副本?

When I run the integration tests it drops the database I've loaded and loads the test fixtures (as expected). How can I change this behaviour and keep the copy of my production DB I've loaded?

推荐答案

集成测试调用db:test:prepare,调用db:test:clone_structure,调用db:structure:dump和db:test:purge

Integration tests calls db:test:prepare which calls db:test:clone_structure which calls db:structure:dump and db:test:purge

您可以编写自己的任务

namespace :your_namespace do
  Rake::TestTask.new(:integration => "db:migrate(if you want") do |t|
    t.libs << "test"
    t.pattern = 'test/integration/**/*_test.rb'
    t.verbose = true
  end
end

这篇关于如何在不删除数据库内容的情况下运行Rails集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:55