#!/bin/sh

set -e

export GEM_HOME=/tmp/jruby_gems

mkdir -p "${GEM_HOME}/gems" "${GEM_HOME}/specifications"

for gem in concurrent-ruby concurrent-ruby-edge diff-lcs rspec-core rspec-expectations rspec-mocks rspec-support timecop; do
    gem_version=$(find /usr/share/rubygems-integration/all/gems -maxdepth 1 -type d -regex ".*/${gem}-[0-9\.]+" -printf "%f\n")
    echo "installing ${gem_version} gem into temporary GEM_HOME for jruby ..."
    cp -rs "/usr/share/rubygems-integration/all/gems/${gem_version}" "${GEM_HOME}/gems"
    cp -rs "/usr/share/rubygems-integration/all/specifications/${gem_version}.gemspec" "${GEM_HOME}/specifications"
done

if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "armel" ]; then
    # try to avoid timeouts on slow architecture
    sed -i 's,Timeout.timeout(10),Timeout.timeout(30),' spec/concurrent/executor/executor_service_shared.rb
fi

jruby /usr/bin/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb --no-color --backtrace --order defined --format documentation
