Skip to content

Commit

Permalink
warn user that installation will fail if she doesn't have necessary w…
Browse files Browse the repository at this point in the history
…rite permission
  • Loading branch information
Mizou04 committed Sep 8, 2023
1 parent 61a627e commit f8c9c33
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/ruby-install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/cli-tests/no_permission_warn_test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f8c9c33

Please sign in to comment.