ruby - 无法使用 docker compose 执行 rake rspec 单元测试
问题描述
当我rake spec
对这个 rake 文件执行时,docker compose 会出现,然后在执行单元测试之前它会关闭。如果我删除最后一个运行的命令docker-compose down
它工作正常
如何修改脚本以便它可以运行docker-compose up --detach
,然后run the unit tests
,然后docker-compose down
在单元测试完成后运行?
我尝试添加睡眠,但效果不佳。
在我的Rakefile:
Spec::Core::RakeTask.new(:spec)
# start docker compose.
# we use the system command to wait until docker compose is up and running before starting unit tests
system("docker-compose up --detach")
# run unit tests
task :default => :spec
# stop docker compose
system("docker-compose down")
解决方案
我认为你的问题不是关于,docker
而是关于rake
. Rake(如 make)允许您将依赖项添加到任务中,我们可以使用依赖项链接来安排任务的顺序:
task :docker_up do
system("docker-compose up --detach")
end
task :docker_down do
system("docker-compose down")
end
task :default => [:docker_up, :spec, :docker_down]
这是您可以了解如何使用 rake的主题
推荐阅读
- ssl - 如何在 ubuntu 18.04 上从 apache 中删除 ssl 配置文件
- bash - 如果上一个命令成功,则在 bash 中运行命令,bash 如何确定命令是否成功
- android - 如何使用 Bitbucket Pipeline 将 adk 上传到 Bitbucket 下载?
- uart - NXP S32K144 中 DMA 和 eDMA 驱动程序/API 的区别
- html - 如何在 Django 中使用 Bootstrap 类导航栏品牌添加自定义图像作为徽标?
- post - 带参数触发 dag
- linux - 如何在 linux 中访问 sshd_config 文件
- javascript - ERRor :ERROR: 0:161: '=' : 无法从 'const float' 转换为 'highp int'
- javafx - 我的 JavaFX 程序在我的 HP Core i5 笔记本电脑上运行良好,但在旧的 32 位桌面上只显示 Windows 应用程序框架
- python - 在 Pandas 中计算每行唯一列中的真/假值