ruby - 如何让 Aruba 使用不同的 ENV ["HOME"]?

标签 ruby cucumber aruba

来自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/

相关文章:

ruby - "gem update --system"会将 rails 从 2.3.8 更新到 3.0 吗?

ruby-on-rails - "autotest/rails [...] doesn' t [...] 存在。中止”

flash - 如何测试 Flash 应用程序?

使用 Aruba 进行 Ruby gem CLI 测试

php - 如何使用流 stream_socket_client() 在 aruba 中打开 ssl 连接

ruby-on-rails - Rbenv 没有使用正确的版本

ruby - 如何打乱字符串中每个单词的中间字母?

java - 如何根据特征文件位置在cucumber java中创建动态粘合?

ruby-on-rails - 运行 Cucumber 测试时 Rails 应用程序的端口