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
Web-E2E-Testing-from-Ruby
Search
MOROHASHI Kyosuke
December 05, 2017
Programming
5
520
Web-E2E-Testing-from-Ruby
MOROHASHI Kyosuke
December 05, 2017
Tweet
Share
More Decks by MOROHASHI Kyosuke
See All by MOROHASHI Kyosuke
Identifying User Idenity
moro
9
14k
Simplicity on Rails -- RDB, REST and Ruby
moro
14
17k
ちょうどよい Rails E2E テスト/enough-good-rails-e2e-test
moro
5
2.4k
フレームワークを作らない方法/How NOT to build frameworks
moro
4
1.1k
全体がいい感じになるために、私たちRailsをホームにするWeb技術者ができること/let-our-whole-system-grow
moro
2
1.9k
フォームオブジェクトとの向き合い方/Grow Form Objects up
moro
1
1.9k
チームによるいきいきとしたソフトウェア開発/an-alive-team-grows-software
moro
3
3.3k
Joyful user foundation restructuring with Ruby
moro
9
19k
cookpad-17day-tech-internship-2017-git
moro
0
9.4k
Other Decks in Programming
See All in Programming
『改訂新版 良いコード/悪いコードで学ぶ設計入門』活用方法−爆速でスキルアップする!効果的な学習アプローチ / effective-learning-of-good-code
minodriven
28
3.9k
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
Amazon Nova Reelの可能性
hideg
0
180
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
DMMオンラインサロンアプリのSwift化
hayatan
0
160
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
1k
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
240
盆栽転じて家具となる / Bonsai and Furnitures
aereal
0
1.7k
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
Azure AI Foundryのご紹介
qt_luigi
1
140
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
2
2.5k
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.1k
Featured
See All Featured
Building Your Own Lightsaber
phodgson
104
6.2k
Why Our Code Smells
bkeepers
PRO
335
57k
Visualization
eitanlees
146
15k
A designer walks into a library…
pauljervisheath
205
24k
Fireside Chat
paigeccino
34
3.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
170
Six Lessons from altMBA
skipperchong
27
3.6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How to train your dragon (web standard)
notwaldorf
89
5.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
860
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Transcript
Ruby && Webํ໘͔Βݟ͑ͨ ΤϯυπʔΤϯυςετͷ ྺ࢙ͱࢥ͍ग़ ॾڮګհ @moro
‣ (ࣸਅ) ղফͰ͖ͨෆ҆
Kyosuke MOROHASHI moro moro
None
લ࢙
‣ ΞϓϦέʔγϣϯͷܗΛ࡞Δͱςετڥ͕͍ͭͯ͘Δɻ ‣ test/models, test/controllers, test/views … ‣ ʮ୯ମʯςετ͕த৺ Ruby
on Rails
‣ & rspec_rails ‣ spec/models, spec/controllers, …. RSpec
‣ ϞσϧɾϏϡʔɾίϯτϩʔϥΛ౷߹(integrate)ͯ͠ ςετ͢Δɻ ‣ ୯ҰϦΫΤετʹ͓͍ͯɺΞϓϦέʔγϣϯͷ֤ϨΠϠ͕ ҙਤ௨Γ౷߹ͯ͠ಈ͔͘ɺΛςετ͢Δɻ ‣ ෳϦΫΤετʹΘͨΔڍಈ(͋ͷը໘͔Β͜ͷը໘ʹભҠͯͦ͠ΕΛೖྗ…) ςετͰ͖ͳ͍ɻ
Integration test / Request spec
‣ ϒϥβૢ࡞ΛࣗಈԽͯ͠ςετ͢Δ Selenium ͱɺ ‣ ਓؒͷૢ࡞Λهͯ͠ςετέʔεΛ࡞ͬͯ͘ΕΔ Selenium IDE Selenium &
Selenium IDE
‣ ϓϩδΣΫτϝϯόʔ͕ɺຖே࠷৽ͷίʔυΛνΣοΫΞ τͯ͠Ұ௨Γ৮ͬͯΈΔɻԿ͔͋Ε͙͢ʹ͢ɻ खಈͰͷܧଓతE2Eςετ
ෳϦΫΤετʹ·͕ͨΔɺϢʔβʔ͕࣮ࡍʹ͏ γφϦΦʹԊͬͨςετΑͦ͞͏ɻ ͜ͷ࣌Ͱ·ͩखಈςετɺ࣮ߦ͢Δͷ͕େมɻ Selenium IDEͰهͨ͠ςετ͙͢յΕΔɻ ࣮ײͰ͖ͨ͜ͱ
Webrat + Cucumber
‣ ΤϯυπʔΤϯυςετΛɺࣗવݴޠͰ͔͚Δɻ ‣ MVCϨΠϠ௨؏ & ෳΞΫγϣϯ ‣ ࣗવݴޠͰςετ͕͔͚Δɻ ‣ Gherkin
ϑΥʔϚοτ ‣ Given, When, Then / લఏɺ͠ɺͳΒ Cucumber
‣ Cucumber ͷόοΫΤϯυɺWebΞϓϦΛςετ͢Δͨ ΊͷϥΠϒϥϦɻ ‣ ηογϣϯ(cookie)ΛҾ͖ͭ͛Δ ‣ ʮෳϦΫΤετΛॱ൪ʹݺΜͩʯςετ͕͔͚ΔΑ͏ʹ ‣ ϦϯΫϑΥʔϜΛૢ࡞͢Δ(ͭΓͰ͑Δ)API͕͋ͬͨ
Webrat
‣ ࣗવݴޠͰॻ͍ͨ *.feature Λಈ͔ͨ͢ΊͷΈΛ step_definitions ͱͯ͠ॻ͘ɻ ‣ step_definitions ͷதRubyίʔυɻࣗવݴޠͱ ਖ਼نදݱͰϚονϯά͞ΕΔɻ
Cucumber + Webrat
None
‣ Gherkin ςΩετΛϓϩάϥϚͱɺϓϩάϥϚͰͳ͍ਓ ͱɺڞ༗Ͱ͖ͳ͍͔ͨΊͨ͠ɻ ‣ ϏδωεαΠυͷ༷ݕ౼/߹ҙʹ ‣ ݟੵΓ୯ҐʹͬͯΈͨΓ ‣ νʔϜͷ৽ϝϯόʔͷઆ໌ʹ
‣ ։ൃ࣌ͷҙࣝ߹Θͤʹ (feature͚ͩॻ͍ͨੜࣽ͑PRΛϨϏϡʔͨ͠Γ) ࢲͱCucumber
Web ͷɺγφϦΦهड़Ͱ͖ΔE2EࣗಈςετͷΈ Γͪΐ͏ΜΓɻ ޠͰॻ͍ͯ͋ΔͷɺͬͯΈΔͱΘ͔Γ͍͢ɻ ૿͕͑ͨʮຊޠϓϩάϥϛϯάʯʹͳͬͯ͠·͏ͱ ϓϩάϥϚʹͱͬͯࡶͳ͚ͩɻ ࣮ײͰ͖ͨ͜ͱ
“ ࣮ࡍʹɺͦΕΒඇٕज़ܥͷεςʔΫϗϧμʔ ʢརؔऀʣͱҰॹʹςετΛॻ͘ͱ͍͏ɺ ՍۭͷॴͰ͔͠ʹཱͪ·ͤΜɻ https://martinfowler.com/bliki/DynamicTyping.html ( http://bliki-ja.github.io/DynamicTyping/ )
‣ ඞͣ͠ʮॻ͍ͯʯΒΘͳ͚ΕͳΒͳ͍Θ͚Ͱͳ͍ɻ ‣ ಉ͡දݱͰεςʔΫϗϧμʔ͕Έͳڞ௨ཧղ͢Δͷ͕େࣄɻ ‣ ʮεςʔΫϗϧμʔʯʹͪΖΜɺ։ൃνʔϜؚ·ΕΔɻ ‣ ͦͷͨΊͷݴޠޠኮΛҭͯΔͷ͕େͩͬͨɻ Α͘ݴΘΕ·͢ɺɺɺ͚ͩͲ
Capybara
‣ WebratޓAPIͷ͋ΔɺͳϥΠϒϥϦ ‣ υϥΠόΛΓସ͑ͯJavaScriptಈ͔ͤΔΑ͏ʹɻ ‣ SeleniumߴϨϕϧAPIͰ͑ΔΑ͏ʹͳͬͨɻ CapybaraϕϯϦɺͰ͢ΑͶ
JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ ͏ͷ͍͢͝خ͍͠ɻ Capybara APIࣗମͲΜͲΜศརʹͳ͍ͬͯΔɻ JS͕ಈ͘֎෦ϒϥβΛىಈ͢Δͷɺศར͚ͩͲ͍& Τϥʔ͕Θ͔ΓͮΒ͘ͳͬͨɻ ࣮ײͰ͖ͨ͜ͱ
‣ RailsϒʔϜͱͱʹਓؾ্ঢɺߴػೳԽ͕ਐΉɻ ‣ shared example, subject, let, ϞοΫඪ४ఏڙ ‣ RSpec
3ͰAPIͱ(งғؾ)͕มΘΔɻ ‣ test-unit power-assert ͷख़ͱͱʹɺxunitͷ ݟ͕͠ਐΉɻ ಉ࣌ظʹ(ྑ͘ѱ͘)RSpecʹେ͖ͳมԽ͕
Capybara + X season 1
‣ Turnip ‣ RSpecͷϥϯλΠϜͰɺGherkinελΠϧͷςετΛ ࣮ߦͰ͖Δɻ ‣ CukeͷࡶϙΠϯτͩͬͨɺstep definitionsఆٛͱͷ ϚονϯάΛվળ͍ͯ͠Δɻ +
RSpec + Gherkin
‣ feature spec ‣ Capybara APIΛͬͯɺΤϯυπʔΤϯυςετΛ ॻ͚ΔΑ͏ʹͨ͠ɻ ‣ Ұ෦ͷޠኮ(feature, scenario…)Λಋೖ͕ͨ͠ɺ͋͘·
ͰRSpecͷϝιου໊ΤΠϦΞεʹͱͲ·Δɻ ‣ 2017࣌ͩͱɺ͜Ε͕ଟ͔ͳɻ + RSpec - Gherkin
‣ σʔλͷηοτΞοϓ͕ͭΒ͍ɻ ‣ Τϯυ͔ΒผͷΤϯυ·ͰɺେͳΦϒδΣΫτάϥϑ͕ඞཁͱͳΓ͕ͪɻ ‣ ͕͔͔࣌ؒͬͨΓɺҙਤͤ͵ෆશσʔλ͕Ͱ͖ͨΓɻ ‣ Έ߹Θͤͷςετ͕ͭΒ͍ɻ ‣ shared
exampleΛۦͨ݁͠Ռɺݟ௨͕͠ѱ݅͘ଟ͘ͳΔɻ feature spec ͭΒ͍ܥ ͋Δ͋Δ
JavaScript ·ͰؚΉΤϯυπʔΤϯυςετ ͏ͷ͍͢͝خ͍͠ (΄Μ͜Ε) Α͍ΤϯυπʔΤϯυςετΛॻ͘ͷ͍͠ɻ υϝΠϯʹԊͬͨޠኮΛҭͯΔͷɻ ݕূ͖݁͢ՌͷݟۃΊ(ͳΜͱͳ͘Ξαʔτ)ɻ ࣮ײͰ͖ͨ͜ͱ
https://speakerdeck.com/akiinyo/du-miyasuiendotuendotesutogashu-kitai?slide=5
શϨΠϠΛ·ͱΊςετ͢Δʹศར ͚ͩͲɺେ͖͍ͯ͘ςετʹͳΓ͕ͪ ݁Ռͱͯ͠:
Capybara + X season 2
‣ Appium ‣ Web͚ͩͰͳ͘ϞόΠϧΞϓϦࣗಈςετՄೳʹɻ ‣ Rails 5.1+ ͰCapybara͕ඪ४ʹɻ ‣ SystemTestCaseͱͯ͑͠ΔΑ͏ʹͳΓɺRSpecͰ
System Specͱͯ͠αϙʔτɻ ‣ Selenium υϥΠόͰheadless chrome͑ΔΑ͏ʹɻ ͜Ε͔ΒͷΤϯυπʔΤϯυςετ
·ͱΊ
‣ ࣗಈԽ͞Εͨ ‣ ΤϯυπʔΤϯυͷςετ ‣ ͱͯΑ͍ͷͩ ࣮ײͰ͖ͨՁ
‣ ΤϯυπʔΤϯυςετ ‣ େ͖ͯ͘ ‣ ͯ͘ ‣ ॻ͘/ϝϯς͢Δͷ͕ΊΜͲ͍͘͞ɺςετʹͳΓ͕ͪ ͬͨ՝
“ ࣗಈςετΛॻ͘ϓϥΫςΟεੈͷ தʹཱʹ͖ࠜɺࣗͨͪͰࣗಈς ετΛॻ͘ͷ͕ʮ;ͭ͏ʯͳੈͷதʹ ͳΓ·ͨ͠ɻ͜Εେ͖ͳલਐͰ͢ɻ — テスト駆動開発 「付録C」
‣ ͷલͷϑΟʔνϟΛͲ͏͍͏γφϦΦʹͰ͖Δ͔ɺ ͦͷγφϦΦͰͷςετରԿ͔ɺΛΑ͘ߟ͑Δɻ ‣ ύϥϝλϥΠζυςετ(γφϦΦΞτϥΠϯ)ɺ ͏ͪΐͬͱٕज़తʹ͏·͘Εͦ͏ͳؾ͢Δɻ ‣ υϝΠϯνʔϜʹ߹ͬͨޠኮΛҭ͍ͯͯ͘ɻ ͬͨ՝ͱ͖߹͑Δͱ͍͍Ͱ͢ΑͶ
“ ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λ ίϯτϩʔϧ͢Δख๏ͩɻ ུ ʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ ͜ͱͩɻ — テスト駆動開発
「まえがき」
‣ ʮϑΟʔνϟશମʯͪΖΜ࠷ॳ͔Βݟͤͳ͍ɻ ‣ ͰϑΟʔνϟͷࠜຊΛͪͬͪΌ͘࡞ͬͯɺͦͷςετΛ ௨͠ଓ͚Δ͜ͱͰ͖ͦ͏ɻ ‣ ࠜຊԿ͔ɺߟ͑Δɻ ‣ νʔϜͷޠኮ͕ҭ͍ͬͯΕɺ͍ͬͦ͏εϜʔζʹͳΓͦ͏ɻ ʮΤϯυπʔΤϯυʯͷద༻