#!/usr/bin/env bats load test_helper create_executable() { name="${1?}" shift 1 bin="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin" mkdir -p "$bin" { if [ $# -eq 0 ]; then cat - else echo "$@" fi } | sed -Ee '1s/^ +//' > "${bin}/$name" chmod +x "${bin}/$name" } @test "fails with invalid version" { export RBENV_VERSION="2.0" run rbenv-exec ruby -v assert_failure "rbenv: version \`2.0' is not installed (set by RBENV_VERSION environment variable)" } @test "completes with names of executables" { export RBENV_VERSION="2.0" create_executable "ruby" "#!/bin/sh" create_executable "rake" "#!/bin/sh" rbenv-rehash run rbenv-completions exec assert_success assert_output < "${hook_path}/exec/hello.bash" export RBENV_VERSION=system RBENV_HOOK_PATH="$hook_path" run rbenv-exec env assert_success assert_line "HELLO=from hook" } @test "carries original IFS within hooks" { hook_path="${RBENV_TEST_DIR}/rbenv.d" mkdir -p "${hook_path}/exec" cat > "${hook_path}/exec/hello.bash" <" { export RBENV_VERSION="2.0" # emulate `ruby -S' behavior create_executable "ruby" </dev/null; then \$BASH "\$found" else echo "ruby: no Ruby script found in input (LoadError)" >&2 exit 1 fi else echo 'ruby 2.0 (rbenv test)' fi SH create_executable "rake" <