#!/usr/bin/env bash
set -e

binstubs_path="bin"
if [[ -n $CI && $BUNDLE_GEMFILE == */* ]]; then
  binstubs_path="${BUNDLE_GEMFILE%/*}/bin"
fi
export PATH="${binstubs_path}:$PATH"

if [[ $BUNDLE_GEMFILE == *non-rails* ]]; then
  echo "bin/rspec spec-non-rails"
  exec rspec spec-non-rails
fi

status=0
for db in sqlite3 mysql postgres; do
  printf "\e[1;33m[DB] %s\e[m\n" "$db"
  echo "bin/rspec spec"
  DB="$db" rspec spec || status="$?"
done
exit $status
