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
610
0
Share
RSpecと非同期関数テスト
於 TokyuRubyKaigi11 2017/07/29
https://tokyurubykaigi.github.io/tokyu11/
shigeru. nakajima
July 29, 2017
More Decks by shigeru. nakajima
See All by shigeru. nakajima
.NETでruby.wasmを動かしてみた
ledsun
0
51
Introduce dRuby
ledsun
0
540
Watching Ruby in browsers
ledsun
0
210
Using Ruby in the browser is wonderful
ledsun
1
4.8k
Rubyで書いたテトリスをブラウザで動かしてみた
ledsun
0
2.7k
ruby.wasm に関する進捗報告
ledsun
0
1.4k
Hacking Guide of the ruby.wasm
ledsun
0
2k
私の作ったruby.wasm アプリケーション
ledsun
0
860
Load gem from browser
ledsun
2
2.1k
Other Decks in Technology
See All in Technology
Standards et agents IA : un tour d’horizon de MCP, A2A, ADK et plus encore
glaforge
0
160
Introduction to Bill One Development Engineer
sansan33
PRO
0
410
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.3k
AI駆動1on1〜AIに自分を育ててもらう〜
yoshiakiyasuda
0
120
AIが書いたコードを信じられない問題 〜レビュー負荷を下げるために変えたこと〜 / The AI Code Trust Gap: Reducing the Review Burden
bitkey
PRO
6
1.3k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
目的ファーストのハーネス設計 ~ハーネスの変更容易性を高めるための優先順位~
gotalab555
8
2.1k
The Journey of Box Building
tagomoris
4
2.1k
60分で学ぶ最新Webフロントエンド
mizdra
PRO
35
18k
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
390
QGISプラグイン CMChangeDetector
naokimuroki
1
390
「責任あるAIエージェント」こそ自社で開発しよう!
minorun365
9
1.9k
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
190
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
94
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
Test your architecture with Archunit
thirion
1
2.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
520
Building AI with AI
inesmontani
PRO
1
900
The Mindset for Success: Future Career Progression
greggifford
PRO
0
310
Ruling the World: When Life Gets Gamed
codingconduct
0
210
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
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
ͬͱྑ͍ํ๏͕͋Ε ڭ͍͑ͯͩ͘͞