diff --git a/test/rehash.bats b/test/rehash.bats index 6e9e8907..1e4d6d51 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -2,10 +2,17 @@ load test_helper +create_executable() { + local bin="${RBENV_ROOT}/versions/${1}/bin" + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + @test "empty rehash" { assert [ ! -d "${RBENV_ROOT}/shims" ] run rbenv-rehash - assert_success + assert_success "" assert [ -d "${RBENV_ROOT}/shims" ] rmdir "${RBENV_ROOT}/shims" } @@ -14,14 +21,32 @@ load test_helper mkdir -p "${RBENV_ROOT}/shims" chmod -w "${RBENV_ROOT}/shims" run rbenv-rehash - assert_failure - assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" + assert_failure "rbenv: cannot rehash: ${RBENV_ROOT}/shims isn't writable" } @test "rehash in progress" { mkdir -p "${RBENV_ROOT}/shims" touch "${RBENV_ROOT}/shims/.rbenv-shim" run rbenv-rehash - assert_failure - assert_output "rbenv: cannot rehash: ${RBENV_ROOT}/shims/.rbenv-shim exists" + 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" + assert_success "\ + rake + rspec + ruby" } diff --git a/test/shell.bats b/test/shell.bats index 94778985..1a5af662 100644 --- a/test/shell.bats +++ b/test/shell.bats @@ -22,14 +22,13 @@ load test_helper @test "shell change invalid version" { run rbenv-sh-shell 1.2.3 - assert_failure - assert_line "rbenv: version \`1.2.3' not installed" - assert_line "return 1" + assert_failure "\ + rbenv: version \`1.2.3' not installed + return 1" } @test "shell change version" { mkdir -p "${RBENV_ROOT}/versions/1.2.3" run rbenv-sh-shell 1.2.3 assert_success 'export RBENV_VERSION="1.2.3"' - refute_line "return 1" } diff --git a/test/whence.bats b/test/whence.bats new file mode 100644 index 00000000..583a2ca6 --- /dev/null +++ b/test/whence.bats @@ -0,0 +1,28 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin="${RBENV_ROOT}/versions/${1}/bin" + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + +@test "finds versions where present" { + create_executable "1.8" "ruby" + create_executable "1.8" "rake" + create_executable "2.0" "ruby" + create_executable "2.0" "rspec" + + run rbenv-whence ruby + assert_success "\ + 1.8 + 2.0" + + run rbenv-whence rake + assert_success "1.8" + + run rbenv-whence rspec + assert_success "2.0" +} diff --git a/test/which.bats b/test/which.bats new file mode 100644 index 00000000..530c1f4b --- /dev/null +++ b/test/which.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats + +load test_helper + +create_executable() { + local bin + if [[ $1 == */* ]]; then bin="$1" + else bin="${RBENV_ROOT}/versions/${1}/bin" + fi + mkdir -p "$bin" + touch "${bin}/$2" + chmod +x "${bin}/$2" +} + +@test "outputs path to executable" { + create_executable "1.8" "ruby" + create_executable "2.0" "rspec" + + RBENV_VERSION=1.8 run rbenv-which ruby + assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby" + + RBENV_VERSION=2.0 run rbenv-which rspec + assert_success "${RBENV_ROOT}/versions/2.0/bin/rspec" +} + +@test "searches PATH for system version" { + create_executable "${RBENV_TEST_DIR}/bin" "kill-all-humans" + create_executable "${RBENV_ROOT}/shims" "kill-all-humans" + + RBENV_VERSION=system run rbenv-which kill-all-humans + assert_success "${RBENV_TEST_DIR}/bin/kill-all-humans" +} + +@test "version not installed" { + create_executable "2.0" "rspec" + RBENV_VERSION=1.9 run rbenv-which rspec + assert_failure "rbenv: version \`1.9' is not installed" +} + +@test "no executable found" { + create_executable "1.8" "rspec" + RBENV_VERSION=1.8 run rbenv-which rake + assert_failure "rbenv: rake: command not found" +} + +@test "executable found in other versions" { + create_executable "1.8" "ruby" + create_executable "1.9" "rspec" + create_executable "2.0" "rspec" + + RBENV_VERSION=1.8 run rbenv-which rspec + assert_failure "\ + rbenv: rspec: command not found + The \`rspec' command exists in these Ruby versions: + 1.9 + 2.0" +}