1#!/usr/bin/env bats 2 3load test_helper 4 5create_version() { 6 mkdir -p "${RBENV_ROOT}/versions/$1" 7} 8 9setup() { 10 mkdir -p "$RBENV_TEST_DIR" 11 cd "$RBENV_TEST_DIR" 12} 13 14stub_system_ruby() { 15 local stub="${RBENV_TEST_DIR}/bin/ruby" 16 mkdir -p "$(dirname "$stub")" 17 touch "$stub" && chmod +x "$stub" 18} 19 20@test "no versions installed" { 21 stub_system_ruby 22 assert [ ! -d "${RBENV_ROOT}/versions" ] 23 run rbenv-versions 24 assert_success "* system" 25} 26 27@test "not even system ruby available" { 28 PATH="$(path_without ruby)" run rbenv-versions 29 assert_failure 30 assert_output "Warning: no Ruby detected on the system" 31} 32 33@test "bare output no versions installed" { 34 assert [ ! -d "${RBENV_ROOT}/versions" ] 35 run rbenv-versions --bare 36 assert_success "" 37} 38 39@test "single version installed" { 40 stub_system_ruby 41 create_version "1.9" 42 run rbenv-versions 43 assert_success 44 assert_output <<OUT 45* system 46 1.9 47OUT 48} 49 50@test "single version bare" { 51 create_version "1.9" 52 run rbenv-versions --bare 53 assert_success "1.9" 54} 55 56@test "multiple versions" { 57 stub_system_ruby 58 create_version "1.8.7" 59 create_version "1.9.3-p13" 60 create_version "1.9.3-p2" 61 create_version "2.2.10" 62 create_version "2.2.3" 63 create_version "2.2.3-pre.2" 64 run rbenv-versions 65 assert_success 66 assert_output <<OUT 67* system 68 1.8.7 69 1.9.3-p2 70 1.9.3-p13 71 2.2.3-pre.2 72 2.2.3 73 2.2.10 74OUT 75} 76 77@test "indicates current version" { 78 stub_system_ruby 79 create_version "1.9.3" 80 create_version "2.0.0" 81 RBENV_VERSION=1.9.3 run rbenv-versions 82 assert_success 83 assert_output <<OUT 84 system 85* 1.9.3 (set by RBENV_VERSION environment variable) 86 2.0.0 87OUT 88} 89 90@test "bare doesn't indicate current version" { 91 create_version "1.9.3" 92 create_version "2.0.0" 93 RBENV_VERSION=1.9.3 run rbenv-versions --bare 94 assert_success 95 assert_output <<OUT 961.9.3 972.0.0 98OUT 99} 100 101@test "globally selected version" { 102 stub_system_ruby 103 create_version "1.9.3" 104 create_version "2.0.0" 105 cat > "${RBENV_ROOT}/version" <<<"1.9.3" 106 run rbenv-versions 107 assert_success 108 assert_output <<OUT 109 system 110* 1.9.3 (set by ${RBENV_ROOT}/version) 111 2.0.0 112OUT 113} 114 115@test "per-project version" { 116 stub_system_ruby 117 create_version "1.9.3" 118 create_version "2.0.0" 119 cat > ".ruby-version" <<<"1.9.3" 120 run rbenv-versions 121 assert_success 122 assert_output <<OUT 123 system 124* 1.9.3 (set by ${RBENV_TEST_DIR}/.ruby-version) 125 2.0.0 126OUT 127} 128 129@test "ignores non-directories under versions" { 130 create_version "1.9" 131 touch "${RBENV_ROOT}/versions/hello" 132 133 run rbenv-versions --bare 134 assert_success "1.9" 135} 136 137@test "lists symlinks under versions" { 138 create_version "1.8.7" 139 ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" 140 141 run rbenv-versions --bare 142 assert_success 143 assert_output <<OUT 1441.8 1451.8.7 146OUT 147} 148 149@test "doesn't list symlink aliases when --skip-aliases" { 150 create_version "1.8.7" 151 ln -s "1.8.7" "${RBENV_ROOT}/versions/1.8" 152 mkdir moo 153 ln -s "${PWD}/moo" "${RBENV_ROOT}/versions/1.9" 154 155 run rbenv-versions --bare --skip-aliases 156 assert_success 157 158 assert_output <<OUT 1591.8.7 1601.9 161OUT 162} 163