You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

  1. #!/usr/bin/env bats
  2. load test_helper
  3. create_hook() {
  4. mkdir -p "$1/$2"
  5. touch "$1/$2/$3"
  6. }
  7. @test "prints usage help given no argument" {
  8. run rbenv-hooks
  9. assert_failure "Usage: rbenv hooks <command>"
  10. }
  11. @test "prints list of hooks" {
  12. path1="${RBENV_TEST_DIR}/rbenv.d"
  13. path2="${RBENV_TEST_DIR}/etc/rbenv_hooks"
  14. create_hook "$path1" exec "hello.bash"
  15. create_hook "$path1" exec "ahoy.bash"
  16. create_hook "$path1" exec "invalid.sh"
  17. create_hook "$path1" which "boom.bash"
  18. create_hook "$path2" exec "bueno.bash"
  19. RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
  20. assert_success
  21. assert_output <<OUT
  22. ${RBENV_TEST_DIR}/rbenv.d/exec/ahoy.bash
  23. ${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash
  24. ${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash
  25. OUT
  26. }
  27. @test "supports hook paths with spaces" {
  28. path1="${RBENV_TEST_DIR}/my hooks/rbenv.d"
  29. path2="${RBENV_TEST_DIR}/etc/rbenv hooks"
  30. create_hook "$path1" exec "hello.bash"
  31. create_hook "$path2" exec "ahoy.bash"
  32. RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec
  33. assert_success
  34. assert_output <<OUT
  35. ${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash
  36. ${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash
  37. OUT
  38. }
  39. @test "resolves relative paths" {
  40. path="${RBENV_TEST_DIR}/rbenv.d"
  41. create_hook "$path" exec "hello.bash"
  42. mkdir -p "$HOME"
  43. RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec
  44. assert_success "${RBENV_TEST_DIR}/rbenv.d/exec/hello.bash"
  45. }
  46. @test "resolves symlinks" {
  47. path="${RBENV_TEST_DIR}/rbenv.d"
  48. mkdir -p "${path}/exec"
  49. mkdir -p "$HOME"
  50. touch "${HOME}/hola.bash"
  51. ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
  52. RBENV_HOOK_PATH="$path" run rbenv-hooks exec
  53. assert_success "${HOME}/hola.bash"
  54. }