Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RSpecと非同期関数テスト
Search
shigeru. nakajima
July 29, 2017
Technology
640
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RSpecと非同期関数テスト
於 TokyuRubyKaigi11 2017/07/29
https://tokyurubykaigi.github.io/tokyu11/
shigeru. nakajima
July 29, 2017
Transcript
16 slides
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
ͬͱྑ͍ํ๏͕͋Ε ڭ͍͑ͯͩ͘͞
More Decks by shigeru. nakajima
See All by shigeru. nakajima
.NETでruby.wasmを動かしてみた
ledsun
0
130
Introduce dRuby
ledsun
0
590
Watching Ruby in browsers
ledsun
0
380
Using Ruby in the browser is wonderful
ledsun
1
5.5k
Rubyで書いたテトリスをブラウザで動かしてみた
ledsun
0
2.8k
ruby.wasm に関する進捗報告
ledsun
0
1.6k
Hacking Guide of the ruby.wasm
ledsun
0
2.2k
私の作ったruby.wasm アプリケーション
ledsun
0
930
Load gem from browser
ledsun
2
2.3k
Other Decks in Technology
See All in Technology
対話 AI プラットフォーム「アイブリー」で実践する自然言語処理と事業開発
ivry_presentationmaterials
0
260
New Relicのアラート対応をClaude Codeで自動修正するワークフローを作った話
manabuseki
3
770
認知負荷の減らし方 ~開発にも日常業務にも活かせるノウハウ~
minorun365
PRO
21
25k
20261119_AgentCore
takuyay0ne
2
360
ワークフローからハーネスへ — Web フレームワークの作者たちが AI エージェントに向かう理由
azukiazusa1
4
4.2k
DMMのプラットフォーム基盤で実践する、AI駆動の「攻め」とAI攻撃からの「守り」のアーキテクチャ設計〜SSoTとSoftwareFactory〜
i35_267
1
110
Webメール開発を大幅に変えたJMAPというゲームチェンジャー
tascript
10
6.5k
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
280
GitHub Advanced Securityはどのようにセキュリティインシデントを防ぐのか
yuriemori
0
140
社内アプリ基盤「Quartz」による、 非エンジニアとAIに本番デプロイを 任せても壊れないプラットフォームの設計
staka121
PRO
1
570
猫でもわかるKiro初心者編(2026年11月版)
kentapapa
1
160
DevOps Agent に Athena で アカウント横断の調査をさせてみた + Config の高度なクエリ便利だよ!って話 / #opsmethod 6
masahirokawahara
0
110
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
350
Making the Leap to Tech Lead
cromwellryan
135
10k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
660
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Rails Girls Zürich Keynote
gr2m
96
14k
The Curious Case for Waylosing
cassininazir
1
630
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
510
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
2
550
Designing Powerful Visuals for Engaging Learning
tmiket
1
670
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
For a Future-Friendly Web
brad_frost
184
11k