gpt4 book ai didi

ruby - 如何使用 Aruba 测试在主文件夹中创建文件

转载 作者:数据小太阳 更新时间:2023-10-29 07:56:01 25 4
gpt4 key购买 nike

我想用 Aruba 和 Cucumber 测试 Ruby 命令行应用程序。该应用程序有一个开关,用于在当前用户的主文件夹中创建一个点文件(例如 .my_app)。我不希望应用程序在运行 Aruba 测试时在用户的主文件夹中创建文件。

我正在寻找一种在步骤定义内创建临时工作目录的方法,该方法将创建临时文件夹并在运行命令行应用程序时修改路径标志。或者 Aruba 中是否内置了一些已经提供类似功能的功能?

样本测试:

Feature: Initialize for user
Scenario: Create a dot file in the user's home directory
When I run `touch ~/.my_test_file`
Then a file named "~/.my_test_file" should exist

最佳答案

在你的env.rb :

Before do
set_env 'HOME', File.expand_path(File.join(current_dir, 'home'))
FileUtils.mkdir_p ENV['HOME']
end

如果您将此与 Aruba 一起使用,则 Aruba 将使用 <project_root>/tmp/aruba/home .然后,Aruba 为您提供了一些不错的 cucumber 步骤来验证文件是否已创建、是否存在等。

编辑:我在我的博客上写了一篇完整的文章:http://ariejan.net/2014/04/15/testing-home-with-cucumber-and-aruba/

关于ruby - 如何使用 Aruba 测试在主文件夹中创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23002871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com