rbenv-ruby-build/test/hooks.bats
Mislav Marohnić cde170b581
Suggest rbenv global if there is no explicit global setting (#2052)
Upon installing their first Ruby version on the system, the user may want to set it as their default; otherwise the default will remain "system" and any `gem install` attempts will fail with a permission error.

This suggestion is skipped if the user already has chosen an explicit default, even if it's "system".
2022-09-25 11:20:43 +02:00

57 lines
1.2 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
export RBENV_ROOT="${TMP}/rbenv"
export HOOK_PATH="${TMP}/i has hooks"
mkdir -p "$HOOK_PATH"
}
@test "rbenv-install hooks" {
cat > "${HOOK_PATH}/install.bash" <<OUT
before_install 'echo before: \$PREFIX'
after_install 'echo after: \$STATUS'
OUT
stub rbenv-hooks "install : echo '$HOOK_PATH'/install.bash"
stub rbenv-rehash "echo rehashed"
stub rbenv-version-file "echo .ruby-version"
definition="${TMP}/2.0.0"
cat > "$definition" <<<"echo ruby-build"
run rbenv-install "$definition"
assert_success
assert_output <<-OUT
before: ${RBENV_ROOT}/versions/2.0.0
ruby-build
after: 0
rehashed
OUT
}
@test "rbenv-uninstall hooks" {
cat > "${HOOK_PATH}/uninstall.bash" <<OUT
before_uninstall 'echo before: \$PREFIX'
after_uninstall 'echo after.'
rm() {
echo "rm \$@"
command rm "\$@"
}
OUT
stub rbenv-hooks "uninstall : echo '$HOOK_PATH'/uninstall.bash"
stub rbenv-rehash "echo rehashed"
mkdir -p "${RBENV_ROOT}/versions/2.0.0"
run rbenv-uninstall -f 2.0.0
assert_success
assert_output <<-OUT
before: ${RBENV_ROOT}/versions/2.0.0
rm -rf ${RBENV_ROOT}/versions/2.0.0
rehashed
after.
OUT
refute [ -d "${RBENV_ROOT}/versions/2.0.0" ]
}