diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29b3046..6f3a025 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [2.0.2] - 2020-03-10
+### Added
+- Retrieve latest version for gem from rubygems.org
+
## [2.0.1] - 2020-02-19
### Added
- Github issue related functions via the `hub` cli
diff --git a/README.md b/README.md
index 8e94a28..b11b190 100644
--- a/README.md
+++ b/README.md
@@ -194,6 +194,17 @@ files within it's directory.
+
+ | Ruby |
+ Helpers related to ruby infrastructure |
+
+
+ - bl_gem_latest_version: Return the latest version of a gem from rubygems.org
+ - bl_jq_available: Check jq binary is available
+ - bl_curl_available: Check curl binary is available
+
+ |
+
| test-utils |
Helpers for executing tests |
diff --git a/github/lib b/github/lib
index 47da933..fcdce90 100644
--- a/github/lib
+++ b/github/lib
@@ -28,6 +28,8 @@ function bl_hub_download_latest(){
local download_url
local bin_path
+ bl_curl_available
+
if [[ -z "${os_arch}" ]]; then
if [[ "${OSTYPE}" =~ "darwin" ]]; then
os_arch="darwin-amd64"
diff --git a/init b/init
index 3c627c3..953f3ad 100644
--- a/init
+++ b/init
@@ -26,7 +26,7 @@ BASH_LIB_DIR="${BASH_LIB_DIR_RELATIVE}"
# Load the filehandling module for the abspath
# function
-for lib in helpers logging filehandling git github k8s test-utils; do
+for lib in helpers logging filehandling git github k8s test-utils ruby; do
. "${BASH_LIB_DIR_RELATIVE}/${lib}/lib"
done
diff --git a/logging/lib b/logging/lib
index fe29b8b..e229612 100644
--- a/logging/lib
+++ b/logging/lib
@@ -68,4 +68,3 @@ function bl_error(){
function bl_fatal(){
bl_log fatal "${*}"
}
-
diff --git a/ruby/lib b/ruby/lib
new file mode 100644
index 0000000..0ce3900
--- /dev/null
+++ b/ruby/lib
@@ -0,0 +1,23 @@
+: "${BASH_LIB_DIR:?BASH_LIB_DIR must be set. Please source bash-lib/init before other scripts from bash-lib.}"
+
+function bl_jq_available(){
+ type jq >/dev/null || bl_fail "jq not found :("
+}
+
+function bl_curl_available(){
+ type curl >/dev/null || bl_fail "curl not found :("
+}
+
+function bl_gem_latest_version(){
+ bl_jq_available
+ bl_curl_available
+
+ gem="${1:-}"
+
+ if [[ -z "${gem}" ]]; then
+ bl_fail "usage: bl_gem_version "
+ fi
+
+ curl https://rubygems.org/api/v1/gems/${gem}.json \
+ |jq -r '.version'
+}
diff --git a/run-tests b/run-tests
index a8d6e19..332de16 100755
--- a/run-tests
+++ b/run-tests
@@ -5,11 +5,19 @@
# shellcheck disable=SC2086
. "$(dirname ${BASH_SOURCE[0]})/init"
-# Run BATS Tests
+bl_info "Checking the changelog complies with keepachangelog.com format"
+docker run \
+ --rm \
+ -v "${PWD}/CHANGELOG.md:/CHANGELOG.md" \
+ cyberark/parse-a-changelog
+
+bl_info "Running BATS Tests"
"${BASH_LIB_DIR}/tests-for-this-repo/run-bats-tests"
-# Run Python Lint
+bl_info "Running Python Lint"
"${BASH_LIB_DIR}/tests-for-this-repo/run-python-lint"
-# Run gitleaks
+bl_info "Running gitleaks"
"${BASH_LIB_DIR}/tests-for-this-repo/run-gitleaks"
+
+bl_info "Sucess! All tests passed."
diff --git a/tests-for-this-repo/fixtures/ruby/ruby_gems_api_response.json b/tests-for-this-repo/fixtures/ruby/ruby_gems_api_response.json
new file mode 100644
index 0000000..c9ed9d5
--- /dev/null
+++ b/tests-for-this-repo/fixtures/ruby/ruby_gems_api_response.json
@@ -0,0 +1,42 @@
+{
+ "name": "parse_a_changelog",
+ "downloads": 6660,
+ "version": "1.0.1",
+ "version_downloads": 168,
+ "platform": "ruby",
+ "authors": "John Tuttle",
+ "info": "Uses a grammar describing the keep-a-changelog format to attempt to parse a given file.",
+ "licenses": [
+ "Apache-2.0"
+ ],
+ "metadata": {},
+ "yanked": false,
+ "sha": "c081ae854570083ba56097d84a1fc66d47dd31f1a015edcb1ba2cbf9e2a4fe4a",
+ "project_uri": "https://rubygems.org/gems/parse_a_changelog",
+ "gem_uri": "https://rubygems.org/gems/parse_a_changelog-1.0.1.gem",
+ "homepage_uri": "http://github.com/cyberark/parse-a-changelog",
+ "wiki_uri": null,
+ "documentation_uri": "http://www.rubydoc.info/gems/parse_a_changelog/1.0.1",
+ "mailing_list_uri": null,
+ "source_code_uri": null,
+ "bug_tracker_uri": null,
+ "changelog_uri": null,
+ "dependencies": {
+ "development": [
+ {
+ "name": "rspec",
+ "requirements": "~> 3.8"
+ },
+ {
+ "name": "rspec_junit_formatter",
+ "requirements": "~> 0.4.1"
+ }
+ ],
+ "runtime": [
+ {
+ "name": "treetop",
+ "requirements": "~> 1.6"
+ }
+ ]
+ }
+}
diff --git a/tests-for-this-repo/ruby.bats b/tests-for-this-repo/ruby.bats
new file mode 100644
index 0000000..c2cee90
--- /dev/null
+++ b/tests-for-this-repo/ruby.bats
@@ -0,0 +1,56 @@
+. "${BASH_LIB_DIR}/test-utils/bats-support/load.bash"
+. "${BASH_LIB_DIR}/test-utils/bats-assert-1/load.bash"
+
+. "${BASH_LIB_DIR}/init"
+
+teardown(){
+ unset curl
+}
+
+
+@test "bl_jq_available succeeds when jq is available" {
+ jq(){ :; }
+ run bl_jq_available
+ assert_success
+}
+
+@test "bl_jq_available fails when jq is not available" {
+ real_path="${PATH}"
+ PATH=""
+ run bl_jq_available
+ PATH="${real_path}"
+ assert_failure
+ assert_output --partial "jq not found"
+}
+
+@test "bl_curl_available succeeds when jq is available" {
+ jq(){ :; }
+ run bl_curl_available
+ assert_success
+}
+
+@test "bl_curl_available fails when jq is not available" {
+ real_path="${PATH}"
+ PATH=""
+ run bl_curl_available
+ PATH="${real_path}"
+ assert_failure
+ assert_output --partial "curl not found"
+}
+
+@test "bl_gem_latest_version fails when no gem name is supplied" {
+ run bl_gem_latest_version
+ assert_failure
+ assert_output --partial "usage"
+}
+
+@test "bl_gem_latest_version returns only the version number" {
+ curl(){
+ fixtures_dir="${BASH_LIB_DIR}/tests-for-this-repo/fixtures/ruby"
+ cat ${fixtures_dir}/ruby_gems_api_response.json
+ }
+
+ run bl_gem_latest_version parse_a_changelog
+ assert_success
+ assert_output "1.0.1"
+}