Extract common create_hook helper

This commit is contained in:
Jason Karns 2015-12-29 10:53:01 -05:00
parent 2cc2ec160e
commit 5ccba5d7cc
2 changed files with 10 additions and 0 deletions

View file

@ -70,6 +70,7 @@ load test_helper
}
@test "RBENV_HOOK_PATH includes rbenv built-in plugins" {
unset RBENV_HOOK_PATH
run rbenv echo "RBENV_HOOK_PATH"
assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
}

View file

@ -17,6 +17,7 @@ if [ -z "$RBENV_TEST_DIR" ]; then
export RBENV_ROOT="${RBENV_TEST_DIR}/root"
export HOME="${RBENV_TEST_DIR}/home"
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
PATH="${RBENV_TEST_DIR}/bin:$PATH"
@ -129,3 +130,11 @@ path_without() {
path="${path#:}"
echo "${path%:}"
}
create_hook() {
mkdir -p "${RBENV_HOOK_PATH}/$1"
touch "${RBENV_HOOK_PATH}/$1/$2"
if [ ! -t 0 ]; then
cat > "${RBENV_HOOK_PATH}/$1/$2"
fi
}