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
Automated testing in Ruby 101
Search
Masafumi Okura
March 04, 2023
Programming
1
1.4k
Automated testing in Ruby 101
https://k-ruby.com/kagoshima-rubykaigi02/
Masafumi Okura
March 04, 2023
Tweet
Share
More Decks by Masafumi Okura
See All by Masafumi Okura
Why did my proposals get rejected?
okuramasafumi
1
480
A suggestion for the future of RDoc
okuramasafumi
1
69
15 JSON serializers for Ruby
okuramasafumi
2
130
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
45
Creating gems 101
okuramasafumi
1
85
How NOT to make your DSL terrible
okuramasafumi
0
310
オブジェクトしこう
okuramasafumi
2
220
Debugging Alba
okuramasafumi
1
200
Learning Ruby
okuramasafumi
5
570
Other Decks in Programming
See All in Programming
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
MCP with Cloudflare Workers
yusukebe
2
220
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
120
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
8
1.9k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
160
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
510
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
940
Recoilを剥がしている話
kirik
5
7.1k
Zoneless Testing
rainerhahnekamp
0
120
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
1
230
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
650
Featured
See All Featured
Thoughts on Productivity
jonyablonski
68
4.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
170
Visualization
eitanlees
146
15k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Faster Mobile Websites
deanohume
305
30k
Embracing the Ebb and Flow
colly
84
4.5k
Music & Morning Musume
bryan
46
6.2k
Docker and Python
trallard
42
3.1k
Making Projects Easy
brettharned
116
6k
Adopting Sorbet at Scale
ufuk
73
9.1k
The Language of Interfaces
destraynor
154
24k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Transcript
RubyͰ͡ΊΔࣗಈςετ ࣛࣇౡRubyձٞ02 େխ࢙ʢOKURA Masafumiʣ 2022-03-04, mark MEIZAN
ࣗಈςετ
ॻ͍͍ͯΔਓ—
ࠓͷඪ
ࣗಈςετ ʹ͍ͭͯͷ ֓ཁͷཧղ
ࠓͷ͓ 1. ࣗಈςετʹ͍ͭͯ 2. Rubyʹ͓͚Δࣗಈςετ 3. ྑ͍ࣗಈςετͱ 4. ࣮ԋʂςετϑΝʔετ
ͦͷલʹ
ࣗݾհ
Okura.introduce(self) • ໊લɿେխ࢙ • ॴଐɿϑϦʔϥϯε • ՝֎׆ಈɿKaigi on RailsɺGrow.rbɺRubygems Code
Reading෦ɺ֤छొஃɺOSS׆ಈɺRails GirlsίʔνɺϑΟ ϤϧυϒʔτΩϟϯϓͷΞυόΠβʔ • ॳࣛࣇౡ
1. ࣗಈςετ ʹ͍ͭͯ
ࣗಈςετͱ
ϓϩάϥϜͱͯ͠ ࣮͞Εͨςετ
ϓϩάϥϜͳͷͰ ࣗಈԽ͕؆୯
ςετͳͷͰ ͋ΔछͷݕূΛ ߦ͏
ࣗಈςετʹ͍ͭͯ 1. ࣗಈςετͷԸܙ 2. ࣗಈςετͷछྨ 3. ࣗಈςετͷҙ
1.1 ࣗಈςετͷ Ըܙ
ࣗಈςετԿ͕خ͍͠ͷ͔ʁ • ίʔυʹର͢ΔυΩϡϝϯτʹͳΔ • ίʔυͷWhatΛઆ໌͢Δ • όάͷ࠶ൃʢϦάϨογϣϯʣΛ͙ • ϦϑΝΫλϦϯάͷॿ͚ʹͳΔʢ΄΅ඞਢʣ •
ʢςετΛઌʹॻ͘߹ʣίʔυͷ্࣭͕͕Δ • ʮςετϑΝʔετʯ
1.2 ࣗಈςετͷ छྨ
ࣗಈςετͷछྨ • ୯ମςετʢϢχοτςετʣ • ଞͷίϯϙʔωϯτ͔ΒΓͯ͠ςετ • ݁߹ςετ • ͍͔ͭ͘ͷίϯϙʔωϯτΛΈ߹Θͤͯςετ
1.3 ࣗಈςετͷ ҙ
ࣗಈςετͰҙ͖͢͜ͱ • ʮόά͕ͳ͍ʯ͜ͱͷূ໌ʹͳΒͳ͍ • ʮςετ͕௨ͬͨʂˠόάͬͯͨorzʯΈ͍ͨͳ͜ͱ Α͋͘Δ • ίʔυΛॻ͍͔ͯΒςετΛॻ͘ͱେมʹͳΓ͕ͪ • ςετϑΝʔετͷํָ͕ʢݸਓͷҙݟͰ͢ʣ
͜ͷ࣌Ͱ ͑ͯ ͓͖͍ͨ͜ͱ
ࣗಈςετ ॻ͘ͷ
ࣗಈςετجຊతʹॻ͘ • ʮςετϑΝʔετʯ͔ʮςετϥετʯ͔ͲͪΒͰ Α͍ • MiniTest͔RSpec͔ͲͪΒͰΑ͍ • ࡉ͔͍͜ͱׂͱؾʹ͠ͳ͍ͰΑ͍ • ͱʹ͔͘ॻ͘
ॻ͔ͳ͍ޙչ ΑΓ ॻ͘ޙչ
2. Rubyʹ͓͚Δ ࣗಈςετ
Rubyͷੈքʹ ͨ͘͞Μͷςετ gem͕͋Γ·͢
ςετgemͷখྨ 1. ςετϑϨʔϜϫʔΫ 2. ಛఆ༻్͚DSL 3. αϙʔτϥΠϒϥϦ
2.1 ςετ ϑϨʔϜϫʔΫ
RubyͷςετϑϨʔϜϫʔΫ • RSpec • μϯϩʔυ͕࠷ଟɺ൚༻ςετDSLͰ͋Δ • MiniTest • xUnitܥ౷ɺεϐʔυͱγϯϓϧ͕͞Ϧ •
Test::Unit • ࠷ݹͷςετϑϨʔϜϫʔΫɺxUnitܥ౷
2.2 ಛఆ༻్͚ DSL
ಛఆ༻్͚DSL • Capybara • ϒϥβૢ࡞ͷͨΊͷDSL • Cucumber • ड͚ೖΕςετͷͨΊͷDSLɺຊޠ͕ॻ͚Δ
2.3 αϙʔτ ϥΠϒϥϦ
αϙʔτϥΠϒϥϦ • FactoryBot • ςετσʔλʢߏԽ͞Εͨσʔλʣͷੜ • Faker • ϥϯμϜσʔλʢϝʔϧΞυϨε໊લͳͲʣ •
Timecop • ࣌ؒΛૢ࡞͢Δ
3. ྑ͍ࣗಈςετ ͱ
ྑ͍ࣗಈςετͷϙΠϯτ • ࣗಈςετίʔυͳͷͰɺྑ͍ίʔυͷݪଇΛద༻͢Δ • Մಡੑʢ໋໊ɺཻͷখ͞͞ͳͲʣ • దͳߏԽ • ࣮ߦ࣌ؒͷ͞ •
ແବͳσʔλੜΛආ͚ΔʢಛʹσʔλϕʔεΞΫηε͍ʣ • ୯ମςετʹدͤΔʢ݁߹ςετ͍ʣ
• RSpecͩͱྑ͍ςετʹ͍ͭͯٞʹͳΓ͕ͪ • letͱlet!ͱbeforeͷ͍͚ • contextͱitʹຊޠΛ͑Δ͔ʁ • etc… •
ϩʔΧϧͳ׳शʹै͏ͷ͕٢
4. ࣮ԋʂ ςετϑΝʔετ