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
440
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
280
オブジェクトしこう
okuramasafumi
2
210
Debugging Alba
okuramasafumi
1
190
Learning Ruby
okuramasafumi
5
560
Other Decks in Programming
See All in Programming
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
CSC509 Lecture 09
javiergs
PRO
0
140
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
subpath importsで始めるモック生活
10tera
0
300
受け取る人から提供する人になるということ
little_rubyist
0
230
みんなでプロポーザルを書いてみた
yuriko1211
0
260
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
100
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
Rails Girls Zürich Keynote
gr2m
94
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Gamification - CAS2011
davidbonilla
80
5k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Optimizing for Happiness
mojombo
376
70k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Six Lessons from altMBA
skipperchong
27
3.5k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.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. ࣮ԋʂ ςετϑΝʔετ