문제

From the docs:

Per default Aruba will create a directory tmp/aruba where it performs its file operations.

However, my application uses ENV["HOME"] to create and read a file (~/.foorc), so I need Aruba to use a fake ENV["HOME"].

Do I need to set it in some support-file, or is there a way to tell Aruba to its tmp/aruba for files in ENV["HOME"]?

Here is an excerpt of my code that I am testing (obviously I am testing this with Cucumber/Aruba on a much higher level, but the usage of ENV["HOME"] is what is important here.):

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?
#...

The Specification:

Scenario: todotxt
  Given an empty installation
  When I run `todotxt`
  Then it should pass with:
    """
    Should I create a sample config file? [Y/n]
    """
도움이 되었습니까?

해결책

Looking into the implementation in Aruba itself, I could craft something very similar:

File features/support/aruba.rb, is autoloaded by cucumber and implements the 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

From now on, a directory tmp/aruba is used as $HOME.

Note that in aruba, this temporary path is configurable, and that above code does not take that into consideration. It will break when the tmp path is configured elsewhere.

다른 팁

Aruba offers a step for just that:

Given a mocked home directory

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top