# 取り組んだ課題 https://github.com/ko1/rubyhackchallenge/blob/master/tasks.md#ビルドした-ruby-での-gem-のテスト > 現在、ビルドした Ruby で Gem など、外部ライブラリを、ビルドした Ruby で、他の影響を与えないで適切にテストする方法がありません。 というのも、Gem の場合、Gem のテストのために他の Gem を利用したりする必要があるためです。 区切られた環境(サンドボックス)を用いることで # 成果 * https://gist.github.com/nownabe/b09db191e34206882b66b2e6ae2c7658 * `make install`した先でGemをテストするスクリプト * テストの流れ * Gemを指定するとYAMLの定義に従ってGemのレポジトリをクローン * Gemの依存Gemを`make install`先にインストール * YAMLの定義に従ってテストを実行 * https://github.com/nownabe/docker-rubygems-test (未完成) * 前半、CI用にDockerイメージを作ろうとして、やっぱりRubyをHackしてる感がなくてやめたやつ # 今後 * サンドボックス要件が完全には満たせていないので、ビルドディレクトリにのみ閉じて(`make install`不要)Gemのテストを実行できるように修正する * `/tool`にスクリプトを作り、`make testgem`のような形で実行できるようにする * ある程度、レポジトリやテストコマンドを自動検知できるようにする
Activity
nownabe commentedon Sep 4, 2017
土日で続きをやってみました。
nownabe/ruby@fafe53e
現在はまだいろいろ制限がありますが、
make testgemで環境を汚さずにGemがテストできるようになりました。Usage:
制限:
--enable-shared必須課題
--enable-sharedなしでのテスト (必要?)nownabe commentedon Sep 5, 2017
make testgemを通すために必要な環境構築Debian 9 (Stretch)
CentOS 7
Fedora 25
nownabe commentedon Sep 5, 2017
テスト状況
v2_4_2 / --enable-sharedなし
v2_4_2 / --enable-sharedあり
trunk / --enable-sharedなし
trunk / --enable-sharedあり
hsbt commentedon Sep 5, 2017
@nownabe こんにちは、 @ko1 さんから紹介いただきました。Bundled Gems 全般を僕がみているので、レビューのち本体にマージできそうならマージしたいと思います。
ko1 commentedon Sep 5, 2017
すげーどうでも良い話なんですが、test-all とか test-spec という既存の名前に合わせて、test-gem もしくは test-gems が良さそうに思いました。
nownabe commentedon Sep 5, 2017
@hsbt ありがとうございます!ruby/rubyにPull Request投げる形でよろしいでしょうか?
@ko1 それもそうですね。
test-gemsにします 🙌hsbt commentedon Sep 5, 2017
@nownabe pull request でお願いします!
nownabe commentedon Sep 6, 2017
macOSはEl CapitanからDYLD_LIBRARY_PATHやDYLD_INSERT_LIBRARIESが継承できなくなっているらしい。。。
http://paulbeachsblog.blogspot.jp/2016/03/dyldlibrarypath-and-el-capitan.html
Mac対応は一旦保留 😞
ko1 commentedon Sep 6, 2017
そのために、Mac だと ruby-runner というものを作っているようです。
nownabe commentedon Sep 7, 2017
@ko1 なるほど…!そういえばrunrubyでみました。確認してみます!:pray:
Gem::Ext::Builderが実行するコマンドをなんらかのパッチで差し替える感じかな
nownabe commentedon Sep 10, 2017
https://gist.github.com/nownabe/5d50e0d988d1f6593b91efd0a28a9045
--enable-sharedなしでうまくいかなかったときのログ:ruby-staticがないらしい?nownabe commentedon Sep 10, 2017
nownabe commentedon Sep 10, 2017
--enable-sharedがないとeventmachineがビルドできない。extconf.rbから生成されたMakefileのCPPFLAGSに
-DHAVE_RB_WAIT_FOR_SINGLE_FD -DHAVE_RB_THREAD_FD_SELECTを追加するとビルドできる。https://github.com/eventmachine/eventmachine/blob/master/ext/em.h#L25
https://github.com/eventmachine/eventmachine/blob/master/ext/em.cpp#L623
--enable-sharedありの場合のMakefileは-DHAVE_RB_WAIT_FOR_SINGLE_FD -DHAVE_RB_THREAD_FD_SELECTが定義されている。このへんおっかける
https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1056
https://github.com/eventmachine/eventmachine/blob/master/ext/extconf.rb#L109
nownabe commentedon Sep 18, 2017
--enable-sharedなしとMacでも動くようになったので、Gemを増やしていきたいhttp://bestgems.org/total このへんみつつ
ko1 commentedon Sep 18, 2017
RubyKaigi にいらっしゃいます?
nownabe commentedon Sep 19, 2017
@ko1 すみません今年は参加していません 😭🙏
nownabe commentedon Sep 19, 2017
BestGemsのTop100のGemを試して、trunkでテストが通らないGemの傾向 (2.4ではまだできていない)
nownabe commentedon Sep 20, 2017
今の所test-gemsの環境でのみテストが通らないのは3つ
nownabe commentedon Sep 20, 2017
rspecは、
erb.rbをソースディレクトリに置いたままRUBYLIBで参照させていたのが原因っぽいRSpecのbacktraceをフィルタリングする箇所でtest-gems環境だとパスが
lib/rubyにマッチしないのでフィルタリングできていなかった。https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/backtrace_formatter.rb#L11
ko1 commentedon Sep 21, 2017
そういえば、これを進めて http://www.ruby.or.jp/ja/news/20170804 に出しません?
nownabe commentedon Sep 21, 2017
@ko1 出してみたいです!こんなのあるんですね
nownabe commentedon Sep 21, 2017
@ko1 応募メールに記載する担当者は笹田さんでよろしいでしょうか?
nownabe commentedon Sep 21, 2017
TODO
ruby-runner=>exe/rubyの変更があったので追従する必要がありそうif: { platform: "mac" }のような形でテストを実行する条件を指定できるようにする--depth 1ko1 commentedon Sep 22, 2017
メンターですかね? 私で結構です。
nownabe commentedon Sep 22, 2017
承知しました!
nownabe commentedon Sep 22, 2017
ブログに簡単に使い方をまとめました。
https://blog.nownabe.com/2017/09/22/1133.html
nownabe commentedon Sep 23, 2017
bundlerは一旦保留
nownabe commentedon Sep 24, 2017
テスト用のスクリプト: https://github.com/nownabe/gem_tester/tree/master/scripts
CIで回したい…
nownabe commentedon Oct 11, 2017
TODO
オプションでGemレポジトリのディレクトリを指定できるようにする (CIでキャッシュできるように)