diff --git a/bin/ruby-install b/bin/ruby-install index 3c50ccb7..ccfdc5b1 100755 --- a/bin/ruby-install +++ b/bin/ruby-install @@ -18,6 +18,11 @@ fi init || exit $? +if [[ ! -w "$install_dir" ]]; then + error "Installation directory is not writable by the user: $install_dir" + exit 1 +fi + if [[ $no_reinstall -eq 1 ]] && [[ -x "$install_dir/bin/ruby" ]]; then log "Ruby is already installed into $install_dir" exit diff --git a/test/cli-tests/no_permission_warn_test.sh b/test/cli-tests/no_permission_warn_test.sh new file mode 100755 index 00000000..8a7d2b81 --- /dev/null +++ b/test/cli-tests/no_permission_warn_test.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +. ./test/helper.sh + +test_install_dir="$test_fixtures_dir/no_permission_warn_test" + +function setUp() +{ + mkdir -p "$test_install_dir" + chmod -w "$test_install_dir" +} + +function test_no_install_when_write_permissions_lacking() +{ + local output + local status + local inter="$(ruby-install --install-dir "$test_install_dir" ruby 2>&1)Z5Z5Z$?" + + output="$(echo $inter | awk 'BEGIN { FS="Z5Z5Z" } { print $1 }')" + status="$(echo $inter | awk 'BEGIN { FS="Z5Z5Z" } { print $2 }')" + + assertEquals "did not return 0" 1 $status + assertTrue "did not print a message to STDOUT" \ + '[[ "$output" == *"Installation directory is not writable by the user: ${install_dir}"* ]]' +} + +function tearDown() +{ + rm -rf "$test_install_dir" +} + +SHUNIT_PARENT=$0 . $SHUNIT2