実装マダー?状態だったので華麗にdescribeごとペンディングした話
あの人の実装が終わらないと
こっちのspec実装終われないし本体の実装も入れないんですけど!
しかも!
未実装のfailuresがうざい!
という時に、
そういえばrspecにはpendingがあったはずと思い出し実験したのでメモ。
pendingとskipの違い
- pending
- エラーでpending(成功)、成功したらfailureになる
- pendingにしてたけど待ってたものが実装されたらfailureになり、もうpendingじゃないよ!!ってアピールしてくれる
- itにブロックがないと自動的にpending
- skip
- 実行されない
- 落ちるくらいならskipさせちゃえ!くらいしか使い道が思いつかない
目的
他の実装待ちの部分をpendingにしたいけどpendingの内容は1つずつ表示したい
しかもなるべく簡単な方法で
最終的に
before do pending("あの人待ちでペンディング") # beforeに処理があっても # その処理の前にpendingを書けば放置でおk hoge = hoge.all end
beforeにpendingを入れればitごとにpending扱いしてくれるので
36 examples, 20 failures, 16 pending
こんな感じでテストケースが何個pendingされてるかわかる!素敵!
作業ログ
pending
# ピンポイントでpending # pendingのカウントは1個扱い it "hogeがいい感じにアレとってくること" do pending("ここからpending") expect(@hoge).to be_present end # ここまでpending # 思いっきりpending # pendingのカウントは1個扱い describe "hogeメソッドのテスト" do it "あの人待ちでペンディング" do pending("以降pending") do it "hogeがいい感じにアレとってくること" do expect(@hoge).to be_present end it "hogeがいい感じにアレとってくること" do expect(@hoge).to be_present end end # ここまでが1まとめにpendingされる end end
pending do ~ end に入れると1pending扱いになります
`it` is not available from within an example (e.g. an `it` block) or from constructs that run in the scope of an example (e.g. `before`, `let`, etc). It is only available on an example group (e.g. a `describe` or `context` block).'
変なところにpending do つけるとちゃんと怒られる
skip : skipしたいとこにxつけるだけ
# describeをskip xdescribe "hogeメソッドのテスト" do # contextをskip xcontext "正常系" do # itをskip xit "hogeがいい感じにアレとってくること"
10 pendingとか出してくるけど
# Temporarily skipped with xdescribe
実はskipしてます(実行はしない)
参考