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.

103 lines
2.4 KiB

пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
  1. #!/usr/bin/env bats
  2. load test_helper
  3. setup() {
  4. mkdir -p "${RBENV_TEST_DIR}/myproject"
  5. cd "${RBENV_TEST_DIR}/myproject"
  6. }
  7. @test "no version" {
  8. assert [ ! -e "${PWD}/.ruby-version" ]
  9. run rbenv-local
  10. assert_failure "rbenv: no local version configured for this directory"
  11. }
  12. @test "local version" {
  13. echo "1.2.3" > .ruby-version
  14. run rbenv-local
  15. assert_success "1.2.3"
  16. }
  17. @test "supports legacy .rbenv-version file" {
  18. echo "1.2.3" > .rbenv-version
  19. run rbenv-local
  20. assert_success "1.2.3"
  21. }
  22. @test "local .ruby-version has precedence over .rbenv-version" {
  23. echo "1.8" > .rbenv-version
  24. echo "2.0" > .ruby-version
  25. run rbenv-local
  26. assert_success "2.0"
  27. }
  28. @test "ignores version in parent directory" {
  29. echo "1.2.3" > .ruby-version
  30. mkdir -p "subdir" && cd "subdir"
  31. run rbenv-local
  32. assert_failure
  33. }
  34. @test "ignores RBENV_DIR" {
  35. echo "1.2.3" > .ruby-version
  36. mkdir -p "$HOME"
  37. echo "2.0-home" > "${HOME}/.ruby-version"
  38. RBENV_DIR="$HOME" run rbenv-local
  39. assert_success "1.2.3"
  40. }
  41. @test "sets local version" {
  42. mkdir -p "${RBENV_ROOT}/versions/1.2.3"
  43. run rbenv-local 1.2.3
  44. assert_success ""
  45. assert [ "$(cat .ruby-version)" = "1.2.3" ]
  46. }
  47. @test "changes local version" {
  48. echo "1.0-pre" > .ruby-version
  49. mkdir -p "${RBENV_ROOT}/versions/1.2.3"
  50. run rbenv-local
  51. assert_success "1.0-pre"
  52. run rbenv-local 1.2.3
  53. assert_success ""
  54. assert [ "$(cat .ruby-version)" = "1.2.3" ]
  55. }
  56. @test "renames .rbenv-version to .ruby-version" {
  57. echo "1.8.7" > .rbenv-version
  58. mkdir -p "${RBENV_ROOT}/versions/1.9.3"
  59. run rbenv-local
  60. assert_success "1.8.7"
  61. run rbenv-local "1.9.3"
  62. assert_success
  63. assert_output <<OUT
  64. rbenv: removed existing \`.rbenv-version' file and migrated
  65. local version specification to \`.ruby-version' file
  66. OUT
  67. assert [ ! -e .rbenv-version ]
  68. assert [ "$(cat .ruby-version)" = "1.9.3" ]
  69. }
  70. @test "doesn't rename .rbenv-version if changing the version failed" {
  71. echo "1.8.7" > .rbenv-version
  72. assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ]
  73. run rbenv-local "1.9.3"
  74. assert_failure "rbenv: version \`1.9.3' not installed"
  75. assert [ ! -e .ruby-version ]
  76. assert [ "$(cat .rbenv-version)" = "1.8.7" ]
  77. }
  78. @test "unsets local version" {
  79. touch .ruby-version
  80. run rbenv-local --unset
  81. assert_success ""
  82. assert [ ! -e .rbenv-version ]
  83. }
  84. @test "unsets alternate version file" {
  85. touch .rbenv-version
  86. run rbenv-local --unset
  87. assert_success ""
  88. assert [ ! -e .rbenv-version ]
  89. }