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.