rspec-retry_ex の 紹介
ランダムにおちる
feature/system spec 対策
2019.02.20 Otemachi.rb #14
Yuya Taki
・新卒で某SIerに就職
・渋谷の企業にてRuby on Railsを学ぶ
・2016年10月にENECHANGEにjoin
・よちよち.kotlinを気まぐれに開催
Name : Yuya Taki
GitHub : yuyasat
Qiita : yuyasat
・gemのロゴを書いたり…
(commitはしていない)
・たまにQiitaの記事を書いたり…
・○よ○よ風ゲームをReact.jsで実装した
り
[2]
self.inspect
[1] https://github.com/muramurasan/okuribito
[2] http://poject.herokuapp.com/
[1]
CI(Continuous Integration)で落ちたり通ったり
しませんか?
落ちたり
通ったり
理由は・・・
良くわからない。
でも大抵落ちてるのは・・
あこーでぃおん
も一度回してみたら通る
RebuildしてOKだったらよしとしてもいいのではと
誰かが言っていた
そこで・・
RSpec::Retry
・scenario単位でリトライ
https://github.com/NoRedInk/rspec-
retry
scenario 'create user', retry: 3 do
visit root_path
expect(page).to have_content 'hoge'
fill_in 'user[email]', with: 'fuga@example.com'
fill_in 'user[password]', with: 'password'
click_button 'Submit'
end
一つの申し込みページに複数のアコーディオン
scenario単位でリトライしても複数のうちどこかで
落ちる
特定のexpecだけリトライしたい
expect(page).to have_content 'hoge'
find('label[for=have_bill]').click
expect(find('have_bill_element')).to be_visible
expect(page).to have_content 'fuga'
なかったので作りました。
こんな感じで使います。
retry_ex(count: 3) do
find('label[for=have_bill]').click
expect(find('have_bill_element')).to be_visible
end
実装のポイント
RSpec3.3から導入されたaggregate_faiulresを参考
def run
@counter += 1
yield
rescue RSpec::Expectations::ExpectationNotMetError => e
retry if @counter < count
raise e
end
https://github.com/yuyasat/rspec-retry_ex/blob/master/lib/rspec/retry_ex/retry_handler.rb
まとめ
・CIで落ちたり落ちなかったりするテストに2種類のリトライ機
構で対応
・scenario単位でのリトライできるgemはあった
が、expect単位でリトライできるgemはなかっ
たため、rspec-retry_exというgemを自作
・CIでテストが安定して通るようになった
・ブログ記事
ご清聴ありがとうございました。

ランダムにおちるfeature_system spec対策rspec-retry_ex の 紹介