2

ドキュメントから:

デフォルトでは、Aruba はファイル操作を実行するディレクトリ tmp/aruba を作成します。

ただし、私のアプリケーションはENV["HOME"]ファイル ( ) の作成と読み取り~/.foorcに使用するため、偽の を使用するには Aruba が必要ENV["HOME"]です。

サポートファイルに設定する必要がありますか、それとも Aruba にそのtmp/arubafor ファイルを指定する方法はありますENV["HOME"]か?

これは、私がテストしているコードの抜粋です (明らかに、はるかに高いレベルで 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]
    """
4

2 に答える 2

2

Aruba 自体の実装を調べると、非常によく似たものを作成できます。

ファイルfeatures/support/aruba.rbAroundは cucumber によって自動ロードされ、フックを実装します。

# 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 として使用されます。

aruba では、この一時パスは構成可能であり、上記のコードではそれが考慮されていないことに注意してください。tmp パスが別の場所で構成されていると壊れます。

于 2013-02-02T15:30:07.407 に答える