# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-nanotest
pkgver=0.9.4.1
pkgrel=5
pkgdesc='Extremely mynymal test framework'
arch=(any)
url='https://github.com/mynyml/nanotest'
license=(MIT)
depends=(ruby)
makedepends=(ruby-minitest)
checkdepends=(ruby-rake)
options=(!emptydirs)
source=(https://github.com/mynyml/nanotest/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('8596cea1a553596cf71ff7dc866620e126e0e568946eb64f6ed41a356925ffbb')

prepare() {
  cd nanotest-$pkgver
  # https://github.com/mynyml/nanotest/pull/3
  sed 's/-rubygems //' -i Rakefile
  # https://github.com/mynyml/nanotest/pull/4
  sed 's/MiniTest::Unit::TestCase/MiniTest::Test/' -i test/test_nanotest.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd nanotest-$pkgver
  gem build nanotest.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    nanotest-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd nanotest-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd nanotest-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
