2013-03-07 00:13:50 -05:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
load test_helper
|
2013-03-07 00:13:50 -05:00
|
|
|
|
2013-04-06 06:30:21 -04:00
|
|
|
create_executable() {
|
|
|
|
local bin="${RBENV_ROOT}/versions/${1}/bin"
|
|
|
|
mkdir -p "$bin"
|
|
|
|
touch "${bin}/$2"
|
|
|
|
chmod +x "${bin}/$2"
|
|
|
|
}
|
|
|
|
|
2013-03-07 00:13:50 -05:00
|
|
|
@test "empty rehash" {
|
2013-03-07 15:05:49 -05:00
|
|
|
assert [ ! -d "${RBENV_ROOT}/shims" ]
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_success ""
|
2013-03-07 15:05:49 -05:00
|
|
|
assert [ -d "${RBENV_ROOT}/shims" ]
|
|
|
|
rmdir "${RBENV_ROOT}/shims"
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
|
|
|
|
2013-03-07 15:05:49 -05:00
|
|
|
@test "non-writable shims directory" {
|
|
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
|
|
chmod -w "${RBENV_ROOT}/shims"
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable"
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "rehash in progress" {
|
2013-03-07 15:05:49 -05:00
|
|
|
mkdir -p "${RBENV_ROOT}/shims"
|
|
|
|
touch "${RBENV_ROOT}/shims/.rbenv-shim"
|
2013-03-07 00:13:50 -05:00
|
|
|
run rbenv-rehash
|
2013-04-06 06:30:21 -04:00
|
|
|
assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "creates shims" {
|
|
|
|
create_executable "1.8" "ruby"
|
|
|
|
create_executable "1.8" "rake"
|
|
|
|
create_executable "2.0" "ruby"
|
|
|
|
create_executable "2.0" "rspec"
|
|
|
|
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/ruby" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rake" ]
|
|
|
|
assert [ ! -e "${RBENV_ROOT}/shims/rspec" ]
|
|
|
|
|
|
|
|
run rbenv-rehash
|
|
|
|
assert_success ""
|
|
|
|
|
|
|
|
run ls "${RBENV_ROOT}/shims"
|
2013-04-06 08:10:44 -04:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
rake
|
|
|
|
rspec
|
|
|
|
ruby
|
|
|
|
OUT
|
2013-03-07 00:13:50 -05:00
|
|
|
}
|
2013-04-16 08:01:04 -04:00
|
|
|
|
|
|
|
@test "carries original IFS within hooks" {
|
|
|
|
hook_path="${RBENV_TEST_DIR}/rbenv.d"
|
|
|
|
mkdir -p "${hook_path}/rehash"
|
|
|
|
cat > "${hook_path}/rehash/hello.bash" <<SH
|
|
|
|
hellos=(\$(printf "hello\\tugly world\\nagain"))
|
|
|
|
echo HELLO="\$(printf ":%s" "\${hellos[@]}")"
|
|
|
|
exit
|
|
|
|
SH
|
|
|
|
|
|
|
|
RBENV_HOOK_PATH="$hook_path" IFS=$' \t\n' run rbenv-rehash
|
|
|
|
assert_success
|
|
|
|
assert_output "HELLO=:hello:ugly:world:again"
|
|
|
|
}
|