Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RSpecと非同期関数テスト
Search
shigeru. nakajima
July 29, 2017
Technology
0
520
RSpecと非同期関数テスト
於 TokyuRubyKaigi11 2017/07/29
https://tokyurubykaigi.github.io/tokyu11/
shigeru. nakajima
July 29, 2017
Tweet
Share
More Decks by shigeru. nakajima
See All by shigeru. nakajima
Introduce dRuby
ledsun
0
350
Watching Ruby in browsers
ledsun
0
77
Using Ruby in the browser is wonderful
ledsun
1
2.9k
Rubyで書いたテトリスをブラウザで動かしてみた
ledsun
0
2.3k
ruby.wasm に関する進捗報告
ledsun
0
1.1k
Hacking Guide of the ruby.wasm
ledsun
0
1.5k
私の作ったruby.wasm アプリケーション
ledsun
0
630
Load gem from browser
ledsun
2
1.7k
パラメタライズドテスト
ledsun
0
550
Other Decks in Technology
See All in Technology
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
100
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
360
サーバーなしでWordPress運用、できますよ。
sogaoh
PRO
0
110
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
170
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
360
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
210
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Side Projects
sachag
452
42k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Building Applications with DynamoDB
mza
91
6.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Transcript
Rspecͱඇಉظؔςετ גࣜձࣾϥάβΠΞ தౡ ࣎ @TokyuRubyKaigi 2017/07/29
ࣗݾհ → தౡ ࣎ a.k.a. ledsun → डୗ։ൃͰWebΞϓϦέʔγϣϯΛ։ൃ → Railsܦݧ
࠷ॳʹେࣄͳ͜ͱ → RSpecͰඇಉظؔΛςετ͢Δ ྑ͍ํ๏Λڭ͑ͯཉ͍͠ → RSpecͰͳͯ͘RubyͰ ඇಉظؔΛςετ͢Δ...
Θ͔͍ͬͯΔ͜ͱ → RSpecςετࣦഊͷऩूʹྫ֎Λ͏ → RubyͰαϒεϨουͷྫ֎ ͕ΜΒͳ͍ͱั·͑ΒΕͳ͍
ΜͰ͍Δ͜ͱ ඇಉظؔ ಛʹεϨουΛ࣮ͬͯ Ͳ͏ςετ͢Δʁ
ςετ͍ͨؔ͠ͷ࣮Πϝʔδ def async_func Thread.new do # Կ͔͕͔͔࣌ؒΔॲཧ yield result end
end async_func do |result| # ݁ՌΛΒͬͯԿ͔͢Δ end
Γ͍ͨςετ it 'ඇಉظؔͷࣦഊΛั·͑ΒΕΔ͜ͱ' do async_func do |result| expect(result).to eq(expected_value) #expectͷࣦഊ
=> ྫ֎ end end async_funcͷதผεϨου ผεϨουͷྫ֎ΛΩϟονͰ͖ͳ͍
ࠔΔ͜ͱ expectࣦഊΛݕͰ͖ͳ͍
ϝΠϯεϨουʹྫ֎Λ͢ʹʁ → εϨουมΛฦͯ͠ ݺͼग़͠ݩͰjoin → ྫ֎Ωϟονͯ͠ ϝΠϯεϨουʹ͔ͬͯraise
ϓϩμΫτίʔυʹಛఆͷ࣮Λڧ੍͢Δʁ → ϓϩμΫτίʔυͷ࣮ϛεͬͨΒʁ → ݕͰ͖ͳ͍ → ςετίʔυͷҙຯʁ
Ͱ͖ͦ͏ͳ͜ͱ → RSpecͷࣦഊऩूػߏΛྫ֎ํ͔ࣜΒॻ͖͑Δ failure_notifierลΓ → ඇಉظؔΛεϨουҎ֎Ͱॻ͖͢ Fiberʁ → ඇಉظؔͷ݁ՌΛϝΠϯεϨουʹ͢ ϝΠϯεϨουͰexpect
Ͱ͖ͦ͏ʁ RSpecʹखΛೖΕΔͷେมͦ͏ FiberΑ͘Θ͔Βͳ͍ɺ͜Θ͍
ඇಉظؔͷ݁ՌΛϝΠϯεϨουʹ͢ it 'ඇಉظؔͷࣦഊΛั·͑ΒΕΔ͜ͱ' do result = async_play do |curtail| async_func
do |result| curtail.call result end end expect(result).to eq(expected_value) end ͜ΕͳΒςετͰ͖ͦ͏
ΩϡʔΛ͏ def async_play q = Queue.new yield (reuslt) -> {
q.push result } q.pop end Ωϡʔpop͢Δͱ push͞ΕΔ·Ͱͭ
ࢼ͔ͨͬͨ͠Βgem͋Δ gem 'async_play' results = AsyncPlay.opening{ | curtain | Thread.new
{ curtain.call 1 } } ৄࡉ http://qiita.com/ledsun/items/ 0e1dd4ece43dc56653c7
ͬͱྑ͍ํ๏͕͋Ε ڭ͍͑ͯͩ͘͞