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
340
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
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
190
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
スタートアップで取り組んでいるAzureとMicrosoft 365のセキュリティ対策/How to Improve Azure and Microsoft 365 Security at Startup
yuj1osm
0
210
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
370
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
100
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
530
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Gamification - CAS2011
davidbonilla
80
5.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
How STYLIGHT went responsive
nonsquared
95
5.2k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Designing Experiences People Love
moore
138
23k
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
ͬͱྑ͍ํ๏͕͋Ε ڭ͍͑ͯͩ͘͞