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
470
A suggestion for the future of RDoc
okuramasafumi
1
69
15 JSON serializers for Ruby
okuramasafumi
2
120
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
44
Creating gems 101
okuramasafumi
1
84
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
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
730
Jakarta EE meets AI
ivargrimstad
0
230
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
Refactor your code - refactor yourself
xosofox
1
260
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
620
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
120
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
Become a Pro
speakerdeck
PRO
26
5k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Designing Experiences People Love
moore
138
23k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Done Done
chrislema
181
16k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Faster Mobile Websites
deanohume
305
30k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
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. ࣮ԋʂ ςετϑΝʔετ