add tests for rehash, whence, which

This commit is contained in:
Mislav Marohnić 2013-04-06 12:30:21 +02:00
parent 7a10b64cf7
commit 969af1567a
4 changed files with 118 additions and 9 deletions

View file

@ -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"
}

View file

@ -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"
}

28
test/whence.bats Normal file
View file

@ -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"
}

57
test/which.bats Normal file
View file

@ -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"
}