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
450
A suggestion for the future of RDoc
okuramasafumi
1
66
15 JSON serializers for Ruby
okuramasafumi
2
110
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
39
Creating gems 101
okuramasafumi
1
82
How NOT to make your DSL terrible
okuramasafumi
0
290
オブジェクトしこう
okuramasafumi
2
210
Debugging Alba
okuramasafumi
1
190
Learning Ruby
okuramasafumi
5
560
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.4k
Quine, Polyglot, 良いコード
qnighy
4
650
Djangoの開発環境で工夫したこと - pre-commit / DevContainer
hiroki_yod
1
230
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.3k
Better Code Design in PHP
afilina
PRO
0
130
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
260
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
260
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
6
1.6k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
970
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
CSC509 Lecture 12
javiergs
PRO
0
160
RubyLSPのマルチバイト文字対応
notfounds
0
120
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
How STYLIGHT went responsive
nonsquared
95
5.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Bash Introduction
62gerente
608
210k
Typedesign – Prime Four
hannesfritz
40
2.4k
Designing for Performance
lara
604
68k
Documentation Writing (for coders)
carmenintech
65
4.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
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. ࣮ԋʂ ςετϑΝʔετ