diff --git a/install.sh b/install.sh index 29b83b8..d0c3fdb 100755 --- a/install.sh +++ b/install.sh @@ -48,9 +48,6 @@ VERSION="0.44.1" DIRECTORY="/usr/local/bin" RELEASES_URL="https://github.com/dotenvx/dotenvx/releases" -# for testing purposes -TEST_MODE=0 - # usage usage() { echo "Usage: $0 [options] [command]" @@ -177,6 +174,10 @@ is_ci() { [ -n "$CI" ] && [ $CI != 0 ] } +is_test_mode() { + [ -n "$TEST_MODE" ] && [ $TEST_MODE != 0 ] +} + progress_bar() { if $(is_ci); then echo "--no-progress-meter" @@ -333,9 +334,7 @@ main() { fi } -if test -n "$TEST_MODE"; then - echo "running in test mode" -else +if ! is_test_mode; then main "$@" exit $? fi diff --git a/spec/install_spec.sh b/spec/install_spec.sh index cde8475..14a0e8b 100644 --- a/spec/install_spec.sh +++ b/spec/install_spec.sh @@ -1,12 +1,12 @@ +export CI=1 # because we are running this on github actions and makes testing output easier +export TEST_MODE=1 # set to test mode in order to not run main() for test purposes + Describe 'install.sh' - # source the script without executing it immediately - . ./install.sh + Include install.sh setup() { VERSION="0.44.1" DIRECTORY="./spec/tmp" - CI=1 - TEST_MODE=1 } # remove the dotenvx binary before each test @@ -62,6 +62,55 @@ Describe 'install.sh' End End + Describe 'is_ci()' + It 'returns true' + When call is_ci + The status should equal 0 + End + End + + Describe 'progress_bar()' + It 'returns --no-progress-meter (because is_ci is true)' + When call progress_bar + The status should equal 0 + The output should equal "--no-progress-meter" + End + + Describe 'when is_ci is true' + mock_is_ci_false() { + CI=0 + } + + Before 'mock_is_ci_false' + + It 'returns --progress-bar' + When call progress_bar + The status should equal 0 + The output should equal "--progress-bar" + End + End + End + + Describe 'is_test_mode()' + It 'returns true' + When call is_test_mode + The status should equal 0 + End + + Describe 'typical case when TEST_MODE is false' + mock_is_test_mode_false() { + TEST_MODE=0 + } + + Before 'mock_is_test_mode_false' + + It 'returns false' + When call is_test_mode + The status should equal 1 + End + End + End + Describe 'usage()' It 'displays usage' When call usage