Init RBENV_TEST_DIR properly and only once during test setup

This commit is contained in:
Mislav Marohnić 2015-10-10 19:02:11 +02:00
parent 55f692ba9c
commit 8a0555f8ef

View file

@ -1,18 +1,20 @@
unset RBENV_VERSION unset RBENV_VERSION
unset RBENV_DIR unset RBENV_DIR
# guard against executing this block twice due to bats internals
if [ -z "$RBENV_TEST_DIR" ]; then
RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv"
export RBENV_TEST_DIR="$(mktemp -d "${RBENV_TEST_DIR}.XXX" 2>/dev/null || echo "$RBENV_TEST_DIR")"
if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then
RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv" export RBENV_TEST_DIR="$(realpath "$RBENV_TEST_DIR")"
else else
if [ -n "$RBENV_NATIVE_EXT" ]; then if [ -n "$RBENV_NATIVE_EXT" ]; then
echo "rbenv: failed to load \`realpath' builtin" >&2 echo "rbenv: failed to load \`realpath' builtin" >&2
exit 1 exit 1
fi fi
RBENV_TEST_DIR="$(mktemp -d --tmpdir=$BATS_TMPDIR rbenv.bats.XXX)"
fi fi
# guard against executing this block twice due to bats internals
if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then
export RBENV_ROOT="${RBENV_TEST_DIR}/root" export RBENV_ROOT="${RBENV_TEST_DIR}/root"
export HOME="${RBENV_TEST_DIR}/home" export HOME="${RBENV_TEST_DIR}/home"