1#!/usr/bin/env bats 2 3load test_helper 4 5setup() { 6 mkdir -p "$RBENV_TEST_DIR" 7 cd "$RBENV_TEST_DIR" 8} 9 10@test "reports global file even if it doesn't exist" { 11 assert [ ! -e "${RBENV_ROOT}/version" ] 12 run rbenv-version-origin 13 assert_success "${RBENV_ROOT}/version" 14} 15 16@test "detects global file" { 17 mkdir -p "$RBENV_ROOT" 18 touch "${RBENV_ROOT}/version" 19 run rbenv-version-origin 20 assert_success "${RBENV_ROOT}/version" 21} 22 23@test "detects RBENV_VERSION" { 24 RBENV_VERSION=1 run rbenv-version-origin 25 assert_success "RBENV_VERSION environment variable" 26} 27 28@test "detects local file" { 29 echo "system" > .ruby-version 30 run rbenv-version-origin 31 assert_success "${PWD}/.ruby-version" 32} 33 34@test "reports from hook" { 35 create_hook version-origin test.bash <<<"RBENV_VERSION_ORIGIN=plugin" 36 37 RBENV_VERSION=1 run rbenv-version-origin 38 assert_success "plugin" 39} 40 41@test "carries original IFS within hooks" { 42 create_hook version-origin hello.bash <<SH 43hellos=(\$(printf "hello\\tugly world\\nagain")) 44echo HELLO="\$(printf ":%s" "\${hellos[@]}")" 45SH 46 47 export RBENV_VERSION=system 48 IFS=$' \t\n' run rbenv-version-origin env 49 assert_success 50 assert_line "HELLO=:hello:ugly:world:again" 51} 52 53@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" { 54 RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin 55 assert_success "${RBENV_ROOT}/version" 56} 57