来自the docs :
Per default Aruba will create a directory tmp/aruba where it performs its file operations.
但是,我的应用程序使用 ENV["HOME"]
创建和读取文件 (~/.foorc
),因此我需要 Aruba 使用假 ENV[“HOME”]
。
我是否需要在某些支持文件中设置它,或者有没有办法告诉 Aruba 对于 ENV["HOME"]
中的文件的 tmp/aruba
>?
这是我正在测试的代码的摘录(显然我正在更高级别上使用 Cucumber/Aruba 进行测试,但 ENV["HOME"] 的使用在这里很重要。):
def initialize config_path = ""
if config_path.empty?
@config_path = File.join ENV["HOME"], ".todotxt.cfg"
else
@config_path = config_path
end
if file_exists?
super @config_path
validate
end
end
def file_exists?
File.exists? @config_path
end
#....
ask_to_create unless @config.file_exists?
#...
规范:
Scenario: todotxt
Given an empty installation
When I run `todotxt`
Then it should pass with:
"""
Should I create a sample config file? [Y/n]
"""
最佳答案
研究 Aruba 本身的实现,我可以制作一些非常类似的东西:
文件features/support/aruba.rb,由cucumber自动加载并实现Around
钩子(Hook):
# Temporarily enforce an isolated, fake, homedir.
around do |scenario, block|
@__aruba_original_home = ENV["HOME"]
ENV["HOME"] = File.expand_path(File.join("tmp", "aruba"))
block.call
ENV["HOME"] = @__aruba_original_home
end
从现在开始,目录tmp/aruba将用作$HOME。
请注意,在阿鲁巴岛,这个临时路径是可配置的,上面的代码没有考虑到这一点。当 tmp 路径在其他地方配置时,它将中断。
关于ruby - 如何让 Aruba 使用不同的 ENV ["HOME"]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14478406/