1#!/usr/bin/env bats 2 3load test_helper 4 5@test "shell integration disabled" { 6 run rbenv shell 7 assert_failure "rbenv: shell integration not enabled. Run \`rbenv init' for instructions." 8} 9 10@test "shell integration enabled" { 11 eval "$(rbenv init -)" 12 run rbenv shell 13 assert_success "rbenv: no shell-specific version configured" 14} 15 16@test "no shell version" { 17 mkdir -p "${RBENV_TEST_DIR}/myproject" 18 cd "${RBENV_TEST_DIR}/myproject" 19 echo "1.2.3" > .ruby-version 20 RBENV_VERSION="" run rbenv-sh-shell 21 assert_failure "rbenv: no shell-specific version configured" 22} 23 24@test "shell version" { 25 RBENV_SHELL=bash RBENV_VERSION="1.2.3" run rbenv-sh-shell 26 assert_success 'echo "$RBENV_VERSION"' 27} 28 29@test "shell version (fish)" { 30 RBENV_SHELL=fish RBENV_VERSION="1.2.3" run rbenv-sh-shell 31 assert_success 'echo "$RBENV_VERSION"' 32} 33 34@test "shell revert" { 35 RBENV_SHELL=bash run rbenv-sh-shell - 36 assert_success 37 assert_line 0 'if [ -n "${RBENV_VERSION_OLD+x}" ]; then' 38} 39 40@test "shell revert (fish)" { 41 RBENV_SHELL=fish run rbenv-sh-shell - 42 assert_success 43 assert_line 0 'if set -q RBENV_VERSION_OLD' 44} 45 46@test "shell unset" { 47 RBENV_SHELL=bash run rbenv-sh-shell --unset 48 assert_success 49 assert_output <<OUT 50RBENV_VERSION_OLD="\${RBENV_VERSION-}" 51unset RBENV_VERSION 52OUT 53} 54 55@test "shell unset (fish)" { 56 RBENV_SHELL=fish run rbenv-sh-shell --unset 57 assert_success 58 assert_output <<OUT 59set -gu RBENV_VERSION_OLD "\$RBENV_VERSION" 60set -e RBENV_VERSION 61OUT 62} 63 64@test "shell change invalid version" { 65 run rbenv-sh-shell 1.2.3 66 assert_failure 67 assert_output <<SH 68rbenv: version \`1.2.3' not installed 69false 70SH 71} 72 73@test "shell change version" { 74 mkdir -p "${RBENV_ROOT}/versions/1.2.3" 75 RBENV_SHELL=bash run rbenv-sh-shell 1.2.3 76 assert_success 77 assert_output <<OUT 78RBENV_VERSION_OLD="\${RBENV_VERSION-}" 79export RBENV_VERSION="1.2.3" 80OUT 81} 82 83@test "shell change version (fish)" { 84 mkdir -p "${RBENV_ROOT}/versions/1.2.3" 85 RBENV_SHELL=fish run rbenv-sh-shell 1.2.3 86 assert_success 87 assert_output <<OUT 88set -gu RBENV_VERSION_OLD "\$RBENV_VERSION" 89set -gx RBENV_VERSION "1.2.3" 90OUT 91} 92