Skip to content

Commit 57bb374

Browse files
committed
warn user that installation will fail if she doesn't have necessary write permission
1 parent 61a627e commit 57bb374

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

bin/ruby-install

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ fi
1818

1919
init || exit $?
2020

21+
if [[ ! -w "$install_dir" ]]; then
22+
error "Installation directory is not writable by the user: $install_dir"
23+
exit 1
24+
fi
25+
2126
if [[ $no_reinstall -eq 1 ]] && [[ -x "$install_dir/bin/ruby" ]]; then
2227
log "Ruby is already installed into $install_dir"
2328
exit
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
. ./test/helper.sh
4+
5+
test_install_dir="$test_fixtures_dir/no_permission_warn_test"
6+
7+
function setUp()
8+
{
9+
mkdir -p "$test_install_dir"
10+
chmod -w "$test_install_dir"
11+
}
12+
13+
function test_no_install_when_write_permissions_lacking()
14+
{
15+
local output
16+
local status
17+
local inter="$(ruby-install --install-dir "$test_install_dir" ruby 2>&1)Z5Z5Z$?"
18+
19+
output="$(echo $inter | awk 'BEGIN { FS="Z5Z5Z" } { print $1 }')"
20+
status="$(echo $inter | awk 'BEGIN { FS="Z5Z5Z" } { print $2 }')"
21+
22+
assertEquals "did not return 0" 1 $status
23+
assertTrue "did not print a message to STDOUT" \
24+
'[[ "$output" == *"Installation directory is not writable by the user: ${install_dir}"* ]]'
25+
}
26+
27+
function tearDown()
28+
{
29+
rm -rf "$test_install_dir"
30+
}
31+
32+
SHUNIT_PARENT=$0 . $SHUNIT2

0 commit comments

Comments
 (0)