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
550
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
440
Watching Ruby in browsers
ledsun
0
130
Using Ruby in the browser is wonderful
ledsun
1
3.6k
Rubyで書いたテトリスをブラウザで動かしてみた
ledsun
0
2.5k
ruby.wasm に関する進捗報告
ledsun
0
1.2k
Hacking Guide of the ruby.wasm
ledsun
0
1.6k
私の作ったruby.wasm アプリケーション
ledsun
0
710
Load gem from browser
ledsun
2
1.8k
パラメタライズドテスト
ledsun
0
620
Other Decks in Technology
See All in Technology
ここはMCPの夜明けまえ
nwiizo
32
13k
PagerDuty×ポストモーテムで築く障害対応文化/Building a culture of incident response with PagerDuty and postmortems
aeonpeople
3
530
クラウド開発環境Cloud Workstationsの紹介
yunosukey
0
220
「経験の点」の位置を意識したキャリア形成 / Career development with an awareness of the “point of experience” position
pauli
4
130
Linuxのパッケージ管理とアップデート基礎知識
go_nishimoto
1
700
ガバクラのAWS長期継続割引 ~次の4/1に慌てないために~
hamijay_cloud
1
580
C++26アップデート 2025-03
faithandbrave
0
1.2k
Cross Data Platforms Meetup LT 20250422
tarotaro0129
1
920
Mastraに入門してみた ~AWS CDKを添えて~
tsukuboshi
0
380
エンジニアリングで組織のアウトカムを最速で最大化する!
ham0215
1
280
ペアーズにおける評価ドリブンな AI Agent 開発のご紹介
fukubaka0825
7
1.9k
Pythonデータ分析実践試験 出題傾向や学習のポイントとテクニカルハイライト
terapyon
1
110
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
For a Future-Friendly Web
brad_frost
177
9.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.7k
Adopting Sorbet at Scale
ufuk
76
9.3k
Building Adaptive Systems
keathley
41
2.5k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
550
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
ͬͱྑ͍ํ๏͕͋Ε ڭ͍͑ͯͩ͘͞