# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>

pkgname=ruby3.0-minitest
_gemname=minitest
# Keep version in sync with "Bundled gems" (https://stdgems.org) for the
# packaged Ruby version.
pkgver=5.14.4
pkgrel=1
pkgdesc="Suite of testing facilities supporting TDD, BDD, mocking, and benchmarking for Ruby"
url="https://github.com/seattlerb/minitest"
arch="noarch"
license="MIT"
depends="ruby3.0"
makedepends="ruby3.0-rdoc"
subpackages="$pkgname-doc"
source="https://github.com/seattlerb/minitest/archive/v$pkgver/$_gemname-$pkgver.tar.gz
	https://rubygems.org/downloads/$_gemname-$pkgver.gem
	"
builddir="$srcdir/$_gemname-$pkgver"

prepare() {
	default_prepare

	# Generate gemspec (there's no gemspec in the source).
	gem specification -l --ruby "$srcdir"/$_gemname-$pkgver.gem \
		> "$builddir"/$_gemname.gemspec
}

build() {
	gem build $_gemname.gemspec
}

check() {
	ruby -Ilib -Itest -e "Dir.glob('./test/**/test_*.rb', &method(:require))"
}

package() {
	local gemdir="$pkgdir/$(ruby -e 'puts Gem.default_dir')"
	local geminstdir="$gemdir/gems/$_gemname-$pkgver"

	gem install \
		--local \
		--install-dir "$gemdir" \
		--ignore-dependencies \
		--document ri \
		--verbose \
		$_gemname

	# Remove unnessecary files
	cd "$gemdir"
	rm -rf build_info cache extensions plugins

	cd "$geminstdir"
	rm -rf History.* Manifest.* README.* Rakefile test/
}

doc() {
	pkgdesc="$pkgdesc (ri docs)"

	amove "$(ruby -e 'puts Gem.default_dir')"/doc
}

sha512sums="
e0b780d47e79adcfb68c2d521aa002ad00caefb5820d41d157cfcf34e2c9f987c76e4d31ba1a46b62b18a51c1e84c0add2637f30ab89899e511f3db7b2cea3e3  minitest-5.14.4.tar.gz
f967a11cfce82e167879905082859273b270e8d8e663a0c1c553964a345fb8564547627b8cf97418ac5bda544bb76c1385438ad74ec8e846666dc2952d55c9e9  minitest-5.14.4.gem
"
