Skip to content

Commit

Permalink
Fixing Gemfile.lock overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed May 22, 2022
1 parent a87ce07 commit 2532e22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/gem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gem.configure-cache() {
export LibGem__GemListCache="${LibGem__GemListCacheBase}.${ruby_version}"

local dir=$(dirname "${LibGem__GemListCache}")
[[ -d ${dir} ]] || run "mkdir -p ${dir}" >/dev/null
[[ -d ${dir} ]] || mkdir -p "${dir}" >/dev/null
}

gem.version() {
Expand Down Expand Up @@ -100,8 +100,9 @@ gem.gemfile.version() {
# this ensures the cache is only at most 30 minutes old
gem.cache-installed() {
gem.configure-cache
if [[ ! -s "${LibGem__GemListCache}" || -z $(find "${LibGem__GemListCache}" -mmin -30 2>/dev/null) ]]; then
run "gem list > ${LibGem__GemListCache}" >/dev/null
if [[ ! -s "${LibGem__GemListCache}" || \
-z "$(find "${LibGem__GemListCache}" -mmin -30 2>/dev/null)" ]]; then
gem list > "${LibGem__GemListCache}" >/dev/null
fi
}

Expand Down
20 changes: 12 additions & 8 deletions test/gem_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,31 @@ setup() {
source lib/output.sh
source lib/ruby.sh
source lib/gem.sh
alias ${GrepCommand} ="grep -E -e "
export TMP="$(mktemp -d)"
alias ${GrepCommand}="grep -E -e "
}

teardown() {
rm -f Gemfile.lock
rm -f ${TMP}/Gemfile.lock
}

@test "gem.gemfile.version returns correct 4-part version" {
gem.cache-refresh
set -e
cp test/Gemfile.lock .
result="$(gem.gemfile.version activesupport)"
[ "${result}" == "6.0.3.1" ]
cp test/Gemfile.lock ${TMP}
( cd ${TMP} &&
result="$(gem.gemfile.version activesupport)" &&
[ "${result}" == "6.0.3.1" ]
)
}

@test "gem.gemfile.version returns correct 3-part version" {
gem.cache-refresh
set -e
cp test/Gemfile.lock .
result="$(gem.gemfile.version simple-feed)"
[ "${result}" == "3.0.1" ]
cp test/Gemfile.lock ${TMP}
( cd ${TMP} &&
result="$(gem.gemfile.version simple-feed)" &&
[ "${result}" == "3.0.1" ] )
}

@test "gem.gemfile.version simple-feed == 3.0.1" {
Expand Down

0 comments on commit 2532e22

Please sign in to comment.