2014-08-19 00:59:59 +02:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helper
|
|
|
|
export RBENV_ROOT="${TMP}/rbenv"
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
stub rbenv-hooks 'install : true'
|
|
|
|
stub rbenv-rehash 'true'
|
2022-09-25 11:20:43 +02:00
|
|
|
stub rbenv-version-file 'echo $RBENV_ROOT/version'
|
|
|
|
mkdir -p "$RBENV_ROOT"
|
|
|
|
echo "system" > "$RBENV_ROOT/version"
|
2014-08-19 00:59:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stub_ruby_build() {
|
|
|
|
stub ruby-build "--lib : $BATS_TEST_DIRNAME/../bin/ruby-build --lib" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "install proper" {
|
|
|
|
stub_ruby_build 'echo ruby-build "$@"'
|
|
|
|
|
|
|
|
run rbenv-install 2.1.2
|
|
|
|
assert_success "ruby-build 2.1.2 ${RBENV_ROOT}/versions/2.1.2"
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
unstub rbenv-hooks
|
|
|
|
unstub rbenv-rehash
|
|
|
|
}
|
|
|
|
|
2023-10-11 16:54:58 +02:00
|
|
|
@test "install with flags" {
|
|
|
|
stub_ruby_build 'echo "ruby-build $(inspect_args "$@")"'
|
|
|
|
|
|
|
|
run rbenv-install -kpv 2.1.2 -- --with-configure-opt="hello world"
|
|
|
|
assert_success "ruby-build --keep --verbose --patch 2.1.2 ${RBENV_ROOT}/versions/2.1.2 -- \"--with-configure-opt=hello world\""
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
unstub rbenv-hooks
|
|
|
|
unstub rbenv-rehash
|
|
|
|
}
|
|
|
|
|
2022-09-25 11:20:43 +02:00
|
|
|
@test "suggest running rbenv global after install" {
|
|
|
|
rm -rf "$RBENV_ROOT/version"
|
|
|
|
stub_ruby_build 'echo ruby-build "$@"'
|
|
|
|
|
|
|
|
run rbenv-install 2.1.2
|
|
|
|
assert_success <<OUT
|
|
|
|
ruby-build 2.1.2 ${RBENV_ROOT}/versions/2.1.2
|
|
|
|
|
|
|
|
NOTE: to activate this Ruby version as the new default, run: rbenv global 2.1.2
|
|
|
|
OUT
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
}
|
|
|
|
|
2014-08-19 00:59:59 +02:00
|
|
|
@test "install rbenv local version by default" {
|
|
|
|
stub_ruby_build 'echo ruby-build "$1"'
|
|
|
|
stub rbenv-local 'echo 2.1.2'
|
|
|
|
|
|
|
|
run rbenv-install
|
|
|
|
assert_success "ruby-build 2.1.2"
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
unstub rbenv-local
|
|
|
|
}
|
|
|
|
|
2022-10-03 13:28:58 +02:00
|
|
|
@test "list latest versions" {
|
|
|
|
stub_ruby_build "--list : echo 2.1.2"
|
|
|
|
|
|
|
|
run rbenv-install --list
|
|
|
|
assert_success "2.1.2"
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
}
|
|
|
|
|
2014-08-19 00:59:59 +02:00
|
|
|
@test "list available versions" {
|
|
|
|
stub_ruby_build \
|
|
|
|
"--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'"
|
|
|
|
|
2020-03-03 07:42:13 +01:00
|
|
|
run rbenv-install --list-all
|
2014-08-19 00:59:59 +02:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2019-11-04 14:48:27 +01:00
|
|
|
1.8.7
|
|
|
|
1.9.3-p0
|
|
|
|
1.9.3-p194
|
|
|
|
2.1.2
|
2014-08-19 00:59:59 +02:00
|
|
|
OUT
|
|
|
|
|
|
|
|
unstub ruby-build
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "nonexistent version" {
|
2023-03-06 18:58:00 +01:00
|
|
|
stub_repeated brew false
|
2014-08-19 00:59:59 +02:00
|
|
|
stub_ruby_build 'echo ERROR >&2 && exit 2' \
|
|
|
|
"--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'"
|
|
|
|
|
|
|
|
run rbenv-install 1.9.3
|
|
|
|
assert_failure
|
|
|
|
assert_output <<OUT
|
|
|
|
ERROR
|
|
|
|
|
|
|
|
The following versions contain \`1.9.3' in the name:
|
|
|
|
1.9.3-p0
|
|
|
|
1.9.3-p194
|
|
|
|
|
2023-11-07 18:10:34 +01:00
|
|
|
See all available versions with \`rbenv install --list-all'.
|
2014-08-19 00:59:59 +02:00
|
|
|
|
2014-09-09 07:23:23 +02:00
|
|
|
If the version you need is missing, try upgrading ruby-build:
|
|
|
|
|
2023-11-07 18:10:34 +01:00
|
|
|
git -C ${BATS_TEST_DIRNAME/$HOME\//~/}/.. pull
|
2014-09-09 07:23:23 +02:00
|
|
|
OUT
|
|
|
|
|
2023-03-06 18:58:00 +01:00
|
|
|
unstub brew
|
2014-09-09 07:23:23 +02:00
|
|
|
unstub ruby-build
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Homebrew upgrade instructions" {
|
|
|
|
stub brew "--prefix : echo '${BATS_TEST_DIRNAME%/*}'"
|
|
|
|
stub_ruby_build 'echo ERROR >&2 && exit 2' \
|
|
|
|
"--definitions : true"
|
|
|
|
|
|
|
|
run rbenv-install 1.9.3
|
|
|
|
assert_failure
|
|
|
|
assert_output <<OUT
|
|
|
|
ERROR
|
|
|
|
|
2023-11-07 18:10:34 +01:00
|
|
|
See all available versions with \`rbenv install --list-all'.
|
2014-09-09 07:23:23 +02:00
|
|
|
|
|
|
|
If the version you need is missing, try upgrading ruby-build:
|
|
|
|
|
2023-02-20 16:00:59 +01:00
|
|
|
brew upgrade ruby-build
|
2014-08-19 00:59:59 +02:00
|
|
|
OUT
|
|
|
|
|
2014-09-09 07:23:23 +02:00
|
|
|
unstub brew
|
2014-08-19 00:59:59 +02:00
|
|
|
unstub ruby-build
|
|
|
|
}
|
2014-08-18 19:53:18 +02:00
|
|
|
|
|
|
|
@test "no build definitions from plugins" {
|
2015-10-29 15:40:32 +01:00
|
|
|
refute [ -e "${RBENV_ROOT}/plugins" ]
|
2014-08-18 19:53:18 +02:00
|
|
|
stub_ruby_build 'echo $RUBY_BUILD_DEFINITIONS'
|
|
|
|
|
|
|
|
run rbenv-install 2.1.2
|
|
|
|
assert_success ""
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "some build definitions from plugins" {
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
|
|
|
|
stub_ruby_build "echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"
|
|
|
|
|
|
|
|
run rbenv-install 2.1.2
|
2014-09-06 11:56:39 +02:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
|
|
|
|
2014-08-18 19:53:18 +02:00
|
|
|
${RBENV_ROOT}/plugins/bar/share/ruby-build
|
|
|
|
${RBENV_ROOT}/plugins/foo/share/ruby-build
|
|
|
|
OUT
|
|
|
|
}
|
2014-09-06 11:57:19 +02:00
|
|
|
|
|
|
|
@test "list build definitions from plugins" {
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
|
|
|
|
stub_ruby_build "--definitions : echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"
|
|
|
|
|
2020-03-03 07:42:13 +01:00
|
|
|
run rbenv-install --list-all
|
2014-09-06 11:57:19 +02:00
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2019-11-04 14:48:27 +01:00
|
|
|
|
|
|
|
${RBENV_ROOT}/plugins/bar/share/ruby-build
|
|
|
|
${RBENV_ROOT}/plugins/foo/share/ruby-build
|
2014-09-06 11:57:19 +02:00
|
|
|
OUT
|
|
|
|
}
|
2014-09-09 05:14:33 +02:00
|
|
|
|
|
|
|
@test "completion results include build definitions from plugins" {
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
|
|
|
|
mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
|
|
|
|
stub ruby-build "--definitions : echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"
|
|
|
|
|
|
|
|
run rbenv-install --complete
|
|
|
|
assert_success
|
|
|
|
assert_output <<OUT
|
2015-12-03 21:11:14 +01:00
|
|
|
--list
|
2020-02-19 03:13:35 +01:00
|
|
|
--list-all
|
2015-12-03 21:11:14 +01:00
|
|
|
--force
|
|
|
|
--skip-existing
|
|
|
|
--keep
|
|
|
|
--patch
|
2016-01-15 21:12:53 +01:00
|
|
|
--verbose
|
|
|
|
--version
|
2014-09-09 05:14:33 +02:00
|
|
|
|
|
|
|
${RBENV_ROOT}/plugins/bar/share/ruby-build
|
|
|
|
${RBENV_ROOT}/plugins/foo/share/ruby-build
|
|
|
|
OUT
|
|
|
|
}
|
2014-11-27 05:39:13 +01:00
|
|
|
|
|
|
|
@test "not enough arguments for rbenv-install" {
|
|
|
|
stub_ruby_build
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'install : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:39:13 +01:00
|
|
|
run rbenv-install
|
|
|
|
assert_failure
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "too many arguments for rbenv-install" {
|
|
|
|
stub_ruby_build
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'install : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:39:13 +01:00
|
|
|
run rbenv-install 2.1.1 2.1.2
|
|
|
|
assert_failure
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:39:13 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 05:40:09 +01:00
|
|
|
@test "show help for rbenv-install" {
|
|
|
|
stub_ruby_build
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'install : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:40:09 +01:00
|
|
|
run rbenv-install -h
|
|
|
|
assert_success
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:40:09 +01:00
|
|
|
}
|
|
|
|
|
2015-06-02 20:53:04 +02:00
|
|
|
@test "rbenv-install has usage help preface" {
|
2015-06-03 06:19:41 +02:00
|
|
|
run head "$(which rbenv-install)"
|
2015-06-02 20:53:04 +02:00
|
|
|
assert_output_contains 'Usage: rbenv install'
|
|
|
|
}
|
|
|
|
|
2014-11-27 05:39:13 +01:00
|
|
|
@test "not enough arguments rbenv-uninstall" {
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'uninstall : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:39:13 +01:00
|
|
|
run rbenv-uninstall
|
|
|
|
assert_failure
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "too many arguments for rbenv-uninstall" {
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'uninstall : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:39:13 +01:00
|
|
|
run rbenv-uninstall 2.1.1 2.1.2
|
|
|
|
assert_failure
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:39:13 +01:00
|
|
|
}
|
2014-11-27 05:40:09 +01:00
|
|
|
|
|
|
|
@test "show help for rbenv-uninstall" {
|
2015-06-02 21:42:18 +02:00
|
|
|
stub rbenv-help 'uninstall : true'
|
2015-06-02 15:59:12 +02:00
|
|
|
|
2014-11-27 05:40:09 +01:00
|
|
|
run rbenv-uninstall -h
|
|
|
|
assert_success
|
2015-06-02 15:59:12 +02:00
|
|
|
unstub rbenv-help
|
2014-11-27 05:40:09 +01:00
|
|
|
}
|
2015-06-02 20:53:04 +02:00
|
|
|
|
|
|
|
@test "rbenv-uninstall has usage help preface" {
|
2015-06-03 06:19:41 +02:00
|
|
|
run head "$(which rbenv-uninstall)"
|
2015-06-02 20:53:04 +02:00
|
|
|
assert_output_contains 'Usage: rbenv uninstall'
|
|
|
|
}
|