forked from rbenv/rbenv-installer
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from nodenv/tests
Tests (rebased from commit 0495a2e)
- Loading branch information
1 parent
bafd754
commit 64b6a93
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helper | ||
|
||
@test "reports missing bin in PATH" { | ||
run nodenv-doctor | ||
|
||
assert_failure | ||
assert_line "Checking for \`nodenv' in PATH: not found" | ||
assert_line " Please refer to https://github.com/nodenv/nodenv#installation" | ||
} | ||
|
||
@test "reports missing bin in PATH despite ~/.nodenv" { | ||
with_nodenv_in_home | ||
|
||
run nodenv-doctor | ||
|
||
assert_failure | ||
assert_line "Checking for \`nodenv' in PATH: not found" | ||
assert_line " You seem to have nodenv installed in \`$HOME/.nodenv/bin', but that" | ||
} | ||
|
||
@test "reports successful bin in PATH" { | ||
with_nodenv | ||
|
||
run nodenv-doctor | ||
|
||
assert_line "Checking for \`nodenv' in PATH: $PWD/node_modules/.bin/nodenv" | ||
} | ||
|
||
@test "reports multiple bins in PATH" { | ||
with_nodenv | ||
with_nodenv_in_home | ||
PATH="$HOME/.nodenv/bin:$PATH" | ||
|
||
run nodenv-doctor | ||
|
||
assert_line "Checking for \`nodenv' in PATH: multiple" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
load ../node_modules/bats-support/load | ||
load ../node_modules/bats-assert/load | ||
|
||
# guard against executing this block twice due to bats internals | ||
if [ -z "$TEST_DIR" ]; then | ||
TEST_DIR="${BATS_TMPDIR}/nodenv" | ||
TEST_DIR="$(mktemp -d "${TEST_DIR}.XXX" 2>/dev/null || echo "$TEST_DIR")" | ||
export TEST_DIR | ||
|
||
export HOME="${TEST_DIR}/home" | ||
|
||
PATH=/usr/bin:/bin:/usr/sbin:/sbin | ||
PATH="${BATS_TEST_DIRNAME}/../bin:$PATH" | ||
export PATH | ||
|
||
for nodenv_var in $(env 2>/dev/null | grep '^NODENV_' | cut -d= -f1); do | ||
unset "$nodenv_var" | ||
done | ||
unset nodenv_var | ||
fi | ||
|
||
with_nodenv_in_home() { | ||
local nodenv="$PWD/node_modules/.bin/nodenv" | ||
|
||
mkdir -p "$HOME/.nodenv/bin" | ||
cd "$HOME/.nodenv/bin" || return | ||
ln -sf "$nodenv" nodenv | ||
} | ||
|
||
with_nodenv() { | ||
PATH="$PWD/node_modules/.bin:$PATH" | ||
} |