diff --git a/bin/ruby-install b/bin/ruby-install index 3c50ccb7..5b3ae1a7 100755 --- a/bin/ruby-install +++ b/bin/ruby-install @@ -18,6 +18,10 @@ fi init || exit $? +if [[ ! -w "$install_dir" ]]; then + fail "Installation directory is not writable by the user: $install_dir" +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..7db0b4f1 --- /dev/null +++ b/test/cli-tests/no_permission_warn_test.sh @@ -0,0 +1,30 @@ +#!/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 + + output="$(ruby-install --install-dir "$test_install_dir" ruby 2>&1)" || status=$? + + assertEquals "did not return 0" 255 $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