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
cookpad-17day-tech-internship-2017-tdd
Search
MOROHASHI Kyosuke
August 31, 2017
Programming
0
9.4k
cookpad-17day-tech-internship-2017-tdd
クックパッド17day技術インターンシップの前半、TDDへんの講義資料です
MOROHASHI Kyosuke
August 31, 2017
Tweet
Share
More Decks by MOROHASHI Kyosuke
See All by MOROHASHI Kyosuke
Identifying User Idenity
moro
9
13k
Simplicity on Rails -- RDB, REST and Ruby
moro
14
17k
ちょうどよい Rails E2E テスト/enough-good-rails-e2e-test
moro
5
2.3k
フレームワークを作らない方法/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
Web-E2E-Testing-from-Ruby
moro
5
510
Joyful user foundation restructuring with Ruby
moro
9
19k
Other Decks in Programming
See All in Programming
Recoilを剥がしている話
kirik
5
6.6k
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
350
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
760
Refactor your code - refactor yourself
xosofox
1
260
Zoneless Testing
rainerhahnekamp
0
120
42 best practices for Symfony, a decade later
tucksaun
1
180
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
What's in a price? How to price your products and services
michaelherold
243
12k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
We Have a Design System, Now What?
morganepeng
51
7.3k
Being A Developer After 40
akosma
87
590k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
YesSQL, Process and Tooling at Scale
rocio
169
14k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Optimizing for Happiness
mojombo
376
70k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
For a Future-Friendly Web
brad_frost
175
9.4k
Transcript
TDD: Test Driven Development 2017-08-08 @moro ॾڮګհ
❌ ςεςΟϯάϑϨʔϜϫʔΫͷ͍ํ ɹɹɹ(࣮श࣌ʹݸผʹฉ͍͍ͯͩ͘͞) ⭕ TDDͷૂ͍ ⭕ TDDΛऔಘ͢ΔͨΊͷΧλ ͖ΐ͏͢͜ͱ
What is TDD?
TDD = Test Driven Development
ςετۦಈ։ൃɺϓϩάϥϛϯάதͷෆ҆Λཧ͢Δख๏ ͩɻෆ҆ͱʮ͜ΕࠔͳͳͷͰɺ࠷ॳ͔Βͯ͢Λ ݟ௨ͤΔΘ͚Ͱͳ͍ʯͱ͍͏ਅͬͳײ֮ͷ͜ͱͩɻ ུ 5%%ϓϩάϥϛϯάதͷઃܭஅͱϑΟʔυόοΫͷؒʹ ͋ΔΪϟοϓΛೝࣝ͢Δ͜ͱͰ͋ΓɺͦͷΪϟοϓΛίϯτ ϩʔϧ͢Δٕ๏Ͱ͋Δɻ ςετۦಈ։ൃೖ
‣ ιϑτΣΞΛ࣮ߦ͠ɺͦͷ݁ՌΛ֬ೝͯ࣍͠ʹॻ͘ίʔ υΛܾΊΔɻ ‣ ςεςΟϯάϑϨʔϜϫʔΫ͕ͦΕΛࢧԉͯ͘͠ΕΔɻ ‣ ࣮ߦ͢ΔͨΊͷ४උ(σʔληοτΞοϓͳͲ) ‣ ࣮ߦ݁Ռͷࣗಈ֬ೝ ‣
܁Γฦ࣮͠ߦͷࢧԉ ϑΟʔυόοΫ
Why TDD?
ʮಈ࡞͢Δ͖Ε͍ͳίʔυʯɺϩϯɾδΣϑϦʔ ζͷ͜ͷ؆ܿͳݴ༿ɺ5%% ςετۦಈ։ൃ ͷ ඪͰ͋Δɻಈ࡞͢Δ͖Ε͍ͳίʔυɺ͋ΒΏ Δཧ༝ͰՁ͕͋Δɻ ᴷ,FOU#FDL
ಈ࡞͢Δɺ͖Ε͍ͳίʔυ ͖Ε͍ Ԛ͍ (͙͢ʹ)ಈ͔ͳ͍ ಈ࡞͢Δ ೋͭͷಓ͕͋Δ t-wada: says
‣ TDDͷʮςετʯͱ͍͏χϡΞϯε͕ಠΓา͖ͨ݁͠Ռɺ ʰݟΔ͖ΦϒδΣΫτͷৼΔ͍ʱͩͱ͍͏ཱ͕ݱΕͨɻ ‣ (ࢲ͡͠Μɺ࣮རͱͯ͠ͷҧ͍ͳ͍ͱ͍͏ཱ) ‣ ։ൃΛۦಈ͢ΔɺͦͷͨΊʹظ͢Δʮ;Δ·͍ʯΛ ςετίʔυͰදݱ͠ɺ࣮ߦ͠ɺϑΟʔυόοΫΛಘΔɻ ‣ assertͳΒTDD,
expectͳΒBDDͱ͍͏Ͱͳ͍ɻ FYI: TDDͱBDDͷҧ͍
How to TDD?
How to learn TDD?
कɾഁɾ
‣ Ϩου৽͍͠ίʔυΛॻ͘લʹɺ·ࣦͣഊ͢ΔϢχοτςετΛॻ͘ɻ৽͠ ͍ίʔυͷҙਤΛςετͰࣔ͢ΜͩɻϨουઃܭʹ͍͔ͭͯͬ͠Γߟ͑Δग़ ൃͩɻ ‣ άϦʔϯͱʹ͔͘ςετʹޭ͢ΔίʔυΛॻ͘ɻ࣮ͷ࠷ऴܗΛࢥ͍ඳ͚Δ ͳΒҰؾʹ্͛ͯ͠·͍͍͑ɻͦ͜·Ͱͷࣗ৴͕ͳ͚Εɺ·ͣςετ ʹޭ͢Δఔͷ࣮͚ͩͰߏΘͳ͍ɻ ‣ ϦϑΝΫλϦϯά࣮Λݟ͢ɻςετΛޭͤ͞ΔͨΊʹΒ͔᤻ͨ͠ͷ
ʑΛ͖Ε͍ʹআ͠Α͏ɻॏෳΛऔΓআ͘ɻແବΛল͘ɻҙਤΛ͖ͬΓ͞ ͤΔɻग़དྷΔݶΓ໌ྎͰ͔Γ͍͢ίʔυʹ͠Α͏ɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
5%%ͷαΠΫϧ 1.࣍ͷඪΛߟ͑Δ 2.ͦͷඪΛࣔ͢ςετΛॻ͘ 3.ͦͷςετΛ࣮ߦࣦͯ͠ഊͤ͞Δ 3FE 4.తͷίʔυΛॻ͘ 5.Ͱॻ͍ͨςετΛޭͤ͞Δ (SFFO
6.ςετ͕௨Δ··ͰϦϑΝΫλϦϯάΛߦ ͏ 3FGBDUPS 7.̍ʙΛ܁Γฦ͢ t-wada: says
͖Ε͍ Ԛ͍ (͙͢ʹ)ಈ͔ͳ͍ ಈ࡞͢Δ Red Green Refactoring 5%%ͱԫۚͷճస t-wada: says
͓ ࣌ܭΦϒδΣΫτ
‣ ςεςΟϯάϑϨʔϜϫʔΫ ͦͷଞڥͪΌΜͱಈ͔͘ ࠷ॳͷඪΛߟ͑Δ
$ vim spec/tokei_spec.rb ``` describe '時計' do specify { expect(true).to
be true } end ``` ``` $ bundle exec rspec . Finished in 0.00097 seconds (files took 0.09778 seconds to load) 1 example, 0 failures ``` ࠷ॳͷҰา
‣ RSpec͕ͪΌΜͱΠϯετʔϧ Ͱ͖ͯɺಈ͍͍ͯΔ ղফͰ͖ͨෆ҆
‣ ࣌ɺɺඵΛ࣋ͭ ‣ ʮ10࣌200ඵʯͳͲɺಛఆͷ࣌ࠁΛද͢ ‣ ͱ߹ΘͤΔ͜ͱͰɺಛఆͷ࣌ؒΛࢦ͢ ࣌ܭΦϒδΣΫτͷ༷Λߟ͑Δ
‣ Ϩου৽͍͠ίʔυΛॻ͘લʹɺ·ࣦͣഊ͢ΔϢ χοτςετΛॻ͘ɻ৽͍͠ίʔυͷҙਤΛςετ Ͱࣔ͢ΜͩɻϨουઃܭʹ͍͔ͭͯͬ͠Γߟ͑Δ ग़ൃͩɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
‣ ʮ࣌ܭΫϥεʯͷΫϥε໊Ͳ͏͠Α͏? ‣ Tokei ..? ‣ Clock ? ‣ etc..
࣍ͷඪΛߟ͑Δ
``` describe Clock do specify { expect(Clock.new).to be_an_instance_of(Clock) } end
``` $ bundle exec rspec spec bundler: failed to load command: rspec (/opt/brew/opt/rbenv/versions/2.3.0/bin/rspec) NameError: uninitialized constant Clock ClockΫϥεΛ࡞Γ͍ͨ → ·ͩͳ͍͔ΒΤϥʔʹͳΔͣ
‣ ະॳظԽͷఆClockΛࢀরͨ͠Αɺͱ͍͏Τϥʔ ‣ → ·ͩͳ͍͔ΒΤϥʔʹͳΔͣ ظ௨Γͷཧ༝Ͱͷςετࣦഊ ClockΫϥεΛ࡞Δ४උ
‣ ςετ͕ظ௨Γʹࣦഊ͢Δ͜ͱΛ֬ೝ͢Δͷͱ ͯେࣄɻ ‣ ݟͣΕͷͰΉ͜ͱ͕͋Δɻ ‣ eg: SyntaxErrorΛݟམͱͨ͠··ClockΫϥεΛ ࣮ͯ͠దͳϑΟʔυόοΫʹͳΒͳ͍ ظ௨Γͷཧ༝Ͱͷςετͷࣦഊ
$ mkdir lib $ vim lib/clock.rb ``` class Clock end
``` $ bundle exec rspec spec bundler: failed to load command: rspec (/opt/brew/opt/rbenv/versions/2.3.0/bin/rspec) NameError: uninitialized constant Clock ClockΫϥεΛ࡞Δ → ಡΈࠐ·ͳ͍ͱࢀরͰ͖ͳ͍ͷมΘΒͳ͍ͣ
‣ҙਤͱ߹͍ͬͯΔ? ‣`require`͍ͯ͠ͳ͍͔ΒࢀরͰ͖ͳ͍ ‣→ okΆ͍ ςετࣦഊͷཧ༝Λ֬ೝ͢Δ
``` require 'clock' describe Clock do specify { expect(Clock.new).to be_an_instance_of(Clock)
} end ``` $ bundle exec rspec spec . Finished in 0.00462 seconds (files took 0.09435 seconds to load) 1 example, 0 failures requireͨ͠ˠ͜ΜͲͦ͜௨Δͣ
‣ ϓϩμΫτίʔυͱςετίʔυΛɺͦΕͧΕ Ͳ͜ʹॻ͚Α͍ͷ͔͕Θ͔ͬͨ ‣ ϓϩμΫτίʔυ lib/clock.rb ‣ ςετίʔυ spec/clock_spec.rb ղফͰ͖ͨෆ҆
ςετʹಋ͔Ε࣮ͯ͢Δɺ ͨΊʹ༷Λཧղ͢Δ
‣ ࣌ɺɺඵΛ࣋ͭ ‣ ʮ10࣌200ඵʯͳͲɺಛఆͷ࣌ࠁΛද͢ ‣ ͱ߹ΘͤΔ͜ͱͰɺಛఆͷ࣌ؒΛࢦ͢ ࣌ܭΦϒδΣΫτͷ༷Λߟ͑Δ
࣌ɺɺඵΛ࣋ͭ
‣ ࣌ɺɺඵΛ༩͑ͯΠϯελϯε࡞Δ͜ͱ͕Ͱ͖Δ ‣ Πϯελϯεੜ࣌ʹ༩͑ͨ࣌ɺɺඵΛɺ ͦΕͧΕऔಘͰ͖Δ ‣ ࣌ܭͱͯ͠ෆదͳύϥϝʔλΛ༩͑ͨ߹ʹɺΤϥʔ ͱ͢Δ͜ͱ ࣌ɺɺඵΛ࣋ͭ
‣ 10࣌200ඵͱ͍͏ύϥϝʔλΛ༩͑ͯɺClockΫϥεͷ ΠϯελϯεΛੜͰ͖Δɻ ‣ ੜͨ͠Πϯελϯεͷʮ࣌ʯ10Ͱ͋Δɻ ΠϯελϯεΛͭͬͯ͘ɺ༩͑ͨ࣌ඵΛऔಘͰ͖Δ
‣ 10࣌200ඵͱ͍͏ύϥϝʔλΛ༩͑ͯɺClockΫϥεͷΠ ϯελϯεΛੜͰ͖Δ ‣ ίϯετϥΫλͰɺ࣌ɺɺඵΛ༩͑ΕΑ͍? ‣ ੜͨ͠Πϯελϯεͷʮ࣌ʯ10Ͱ͋Δ ‣ ήολʔ͕͋ΕΑͦ͞͏ ‣
ηολʔ? ݟ͍͑ͯΔݶΓෆཁͦ͏ ࣍ͷඪΛߟ͑Δ
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -2,4 +2,10 @@ require 'clock'
describe Clock do specify { expect(Clock).to be } + + context 'new(10, 20, 00)' do + let(:clock) { Clock.new(10, 20, 0) } + + specify { expect(clock.hour).to eq(10) } + end end ΠϯελϯεΛੜ͢Δςετ
$ bundle exec rspec .F Failures: 1) Clock new(10, 20,
00) Failure/Error: let(:clock) { Clock.new(10, 20, 0) } ArgumentError: wrong number of arguments (given 3, expected 0) # ./spec/clock_spec.rb:7:in `initialize' # ./spec/clock_spec.rb:7:in `new' # ./spec/clock_spec.rb:7:in `block (3 levels) in <top (required)>' # ./spec/clock_spec.rb:9:in `block (3 levels) in <top (required)>' Finished in 0.00186 seconds (files took 0.08364 seconds to load) 2 examples, 1 failure Failed examples: rspec ./spec/clock_spec.rb:9 # Clock new(10, 20, 00) ੜ͢ΔςετˠίϯετϥΫλҾ͕ҧࣦͬͯഊ͢Δͣ
‣ άϦʔϯͱʹ͔͘ςετʹޭ͢ΔίʔυΛॻ͘ɻ ࣮ͷ࠷ऴܗΛࢥ͍ඳ͚ΔͳΒҰؾʹ্͛ͯ͠· ͍͍͑ɻͦ͜·Ͱͷࣗ৴͕ͳ͚Εɺ·ͣςε τʹޭ͢Δఔͷ࣮͚ͩͰߏΘͳ͍ɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
Ծ࣮ (Fake it)
``` --- a/lib/clock.rb +++ b/lib/clock.rb @@ -1,2 +1,8 @@ class
Clock + def initialize(*args) + end + + def hour + 10 + end end ``` Ծ࣮ (Fake it)
‣ ΦϒδΣΫτͷར༻ऀͱͯ͠ظ͢Δ ৼΔ͍ΛɺςετίʔυͰදݱͰ͖ͨ ‣ ҙਤͨ͠ͱ͓ΓʹΤϥʔʹͳͬͨ = ςετίʔυؒҧ͍ͬͯͳͦ͏ ‣ ଈΛฦͤ௨ͬͨ =
·͢·͢Αͦ͞͏ ‣ ͜ΕΛ*ͪΌΜͱ*௨ͦ͏ ղফͰ͖ͨෆ҆
ࡾ֯ଌྔ (Triangulation)
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -8,4 +8,10 @@ describe Clock
do specify { expect(clock.hour).to eq(10) } end + + context 'new(12, 30, 00)' do + let(:clock) { Clock.new(12, 30, 0) } + + specify { expect(clock.hour).to eq(12) } + end end ࡾ֯ଌྔ (Triangulation)
‣ άϦʔϯͱʹ͔͘ςετʹޭ͢ΔίʔυΛॻ͘ɻ ࣮ͷ࠷ऴܗΛࢥ͍ඳ͚ΔͳΒҰؾʹ্͛ͯ͠· ͍͍͑ɻͦ͜·Ͱͷࣗ৴͕ͳ͚Εɺ·ͣςε τʹޭ͢Δఔͷ࣮͚ͩͰߏΘͳ͍ɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
--- a/lib/clock.rb +++ b/lib/clock.rb @@ -1,8 +1,9 @@ class Clock
- def initialize(*args) + def initialize(hour, *) + @hour = hour end def hour - 10 + @hour end end 12:30ͷςετΛ௨͢Α͏ͳɺ࠷ݶͷ࣮
‣ ࠷ॳʹॻ͍ͨςετΛύεͤͨ͞·· ࣍ͷςετ௨͢ɻ ‣ ࣗͷॻ͍ͨίʔυͱ͋Θͤͯͷ3Ͱɺ ಄ͷதͷίʔυͱɺ࣮ͷڑΛଌΔɻ ࡾ֯ଌྔ (Triangulation)
‣ [done] 10࣌200ඵͱ͍͏ύϥϝʔλΛ༩͑ͯɺ ClockΫϥεͷΠϯελϯεΛੜͰ͖Δ ‣ [done] ੜͨ͠Πϯελϯεͷʮ࣌ʯ10Ͱ͋Δ ղফͰ͖ͨෆ҆
ʮಈ࡞͢Δ͖Ε͍ͳίʔυʯɺϩϯɾδΣϑϦʔ ζͷ͜ͷ؆ܿͳݴ༿ɺ5%% ςετۦಈ։ൃ ͷ ඪͰ͋Δɻಈ࡞͢Δ͖Ε͍ͳίʔυɺ͋ΒΏ Δཧ༝ͰՁ͕͋Δɻ ᴷ,FOU#FDL
‣ ϦϑΝΫλϦϯά࣮Λݟ͢ɻςετΛޭͤ͞ΔͨΊ ʹΒ͔᤻ͨ͠ͷʑΛ͖Ε͍ʹআ͠Α͏ɻॏෳΛऔ Γআ͘ɻແବΛল͘ɻҙਤΛ͖ͬΓͤ͞Δɻग़དྷΔݶΓ ໌ྎͰ͔Γ͍͢ίʔυʹ͠Α͏ɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
‣ ςετ͕௨Δ··ͰϦϑΝΫλϦϯάΛߦ͏ ‣ ʮάϦʔϯ to άϦʔϯʯͱ͍͏ݴ͍ճ͠ {ಈ࡞͢Δ && ͖Ε͍ͳ}ίʔυΛࢦͯ͠
--- a/lib/clock.rb +++ b/lib/clock.rb @@ -1,9 +1,8 @@ class Clock
+ attr_reader :hour + def initialize(hour, *) @hour = hour end - def hour - @hour - end end {ಈ࡞͢Δ && ͖Ε͍ͳ}ίʔυΛࢦͯ͠
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -1,8 +1,6 @@ require 'clock'
describe Clock do - specify { expect(Clock.new).to be_an_instance_of(Clock) } - context 'new(10, 20, 00)' do let(:clock) { Clock.new(10, 20, 0) } ςετίʔυϦϑΝΫλϦϯά͢Δ
‣ ςετίʔυϕλʹॻ͔͘ɺDRY-nessΛอ͔ͭ ͕͔ٞΕ͍͕ͯͨɺ͍·ͷ਼ɺςετίʔ υʮίʔυʯͳͷͰͪΌΜͱॻ͘ͱ͍͏ͷ ‣ ॏෳแؚʹΑΔՁͷ͍ςετίʔυמΓࠐ ΜͰ͍͘ ‣ ͨͩמΓ͗ͯ͢ɺ֊ஈ͕ٸʹͳΓ͗͢Δͷྑ͘ͳ͍ FYI:
ΩϨΠͳίʔυ
‣ 10࣌200ඵͱ͍͏ύϥϝʔλΛ༩͑ͯɺClockΫϥεͷΠ ϯελϯεΛੜͰ͖Δ ‣ ίϯετϥΫλͰɺ࣌ɺɺඵΛ༩͑ΕΑ͍? ‣ ੜͨ͠Πϯελϯεͷʮ࣌ʯ10Ͱ͋Δ ‣ 20Ͱ͋Δɻ ‣
ඵ0Ͱ͋Δɻ ࣍ͷඪΛߟ͑Δ
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -5,6 +5,8 @@ describe Clock
do let(:clock) { Clock.new(10, 20, 0) } specify { expect(clock.hour).to eq(10) } + specify { expect(clock.min).to eq(20) } + specify { expect(clock.sec).to eq(0) } end context 'new(12, 30, 00)' do ͱඵʹର͢Δςετˠ#hour, #minϝιου͕ͳ͍ͷͰࣦഊ͢Δͣ
‣ άϦʔϯͱʹ͔͘ςετʹޭ͢ΔίʔυΛॻ͘ɻ ࣮ͷ࠷ऴܗΛࢥ͍ඳ͚ΔͳΒҰؾʹ্͛ͯ͠· ͍͍͑ɻͦ͜·Ͱͷࣗ৴͕ͳ͚Εɺ·ͣςε τʹޭ͢Δఔͷ࣮͚ͩͰߏΘͳ͍ɻ ΞδϟΠϧαϜϥΠୈষςετۦಈ։ൃ
໌നͳ࣮ 0CWJPVT *NQMFNFOUBUJPO
--- a/lib/clock.rb +++ b/lib/clock.rb @@ -1,8 +1,10 @@ class Clock
- attr_reader :hour + attr_reader :hour, :min, :sec - def initialize(hour, *) + def initialize(hour, min, sec) @hour = hour + @min = min + @sec = sec end end ໌നͳ࣮ (Obvious Implementation)
‣ [done] 10࣌200ඵͱ͍͏ύϥϝʔλΛ༩͑ͯɺClockΫ ϥεͷΠϯελϯεΛੜͰ͖Δ ‣ [done] ੜͨ͠Πϯελϯεͷʮ࣌ʯ10Ͱ͋Δ ‣ [done] ʮʯ20Ͱ͋Γɺʮඵʯ0Ͱ͋Δ
ղফͰ͖ͨෆ҆
ͱ߹ΘͤΔ͜ͱͰɺ ಛఆͷ࣌ؒΛࢦ͢
‣ ࣍ͷ࣌ɺલͷ࣌Λಋग़Ͱ͖Δ ‣ ͖ΐ͏ͷʮ10:20ʯ͍͔ͭ ‣ 2017-08-08T10:20:00+JST ͱ߹ΘͤΔ͜ͱͰɺಛఆͷ࣌ؒΛࢦ͢
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -22,4 +22,11 @@ describe Clock
do + + describe '#to_time' do + let(:clock) { Clock.new(10, 20, 0) } + let(:time) { clock.to_time(Date.today) } + + specify { + expect(time.iso8601).to eq ‘2017-08-08T10:20:00+09:00' + } + end end APIΛߟ͑Δ #to_time(<#Date>)͕ૉͦ͏ˠ#to_timeͷ࣮ͳ͍
--- a/lib/clock.rb +++ b/lib/clock.rb @@ -7,6 +7,10 @@ class Clock
@sec = varify_valid_clock_input(sec, 60) end + def to_time(date) + Time.local(2017, 8, 8, 10, 20) + end + private def varify_valid_clock_input(val, max) ճྫ: Ծ࣮
‣ ͱ߹ΘͤΔ͜ͱͰɺಛఆͷ࣌ؒΛࢦ͢ ‣ ຊͷɺ10:20Λදݱ͢Δ ‣ 8/1ͷɺ10:20Λදݱ͢Δ ࡾ֯ଌྔ
‣ ࣍ͷ࣌ɺલͷ࣌Λಋग़Ͱ͖Δ ‣ ͖ΐ͏ͷ 10:20 2017-08-08T10:20:00 JST ‣ 8/1ͷ
10:20 2017-08-01T10:20:00 JST ࡾ֯ଌྔͷexampleΛ۩ମԽ
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -25,8 +25,16 @@ describe Clock
do describe '#to_time' do let(:clock) { Clock.new(10, 20, 0) } - let(:time) { clock.to_time(Date.today) } + context '(Date.today)' do + let(:time) { clock.to_time(Date.today) } - specify { expect(time.iso8601).to eq '2017-08-08T10:20:00+09:00' } + specify { expect(time.iso8601).to eq '2017-08-08T10:20:00+09:00' } + end + + context '(2017-08-01)' do + let(:time) { clock.to_time(Date.new(2017, 8, 1)) } + + specify { expect(time.iso8601).to eq '2017-08-08T10:20:00+09:00' } + end end end ࡾ֯ଌྔ
--- a/lib/clock.rb +++ b/lib/clock.rb @@ -8,7 +8,7 @@ class Clock
end def to_time(date) - Time.local(2017, 8, 8, 10, 20) + Time.local(date.year, date.month, date.day, @hour, @min, @sec) end private ࡾ֯ଌྔ
--- a/spec/clock_spec.rb +++ b/spec/clock_spec.rb @@ -26,7 +26,7 @@ describe Clock
do describe '#to_time' do let(:clock) { Clock.new(10, 20, 0) } context '(Date.today)' do - let(:time) { clock.to_time(Date.today) } + let(:time) { clock.to_time(Date.new(2017, 8, 8)) } specify { expect(time.iso8601).to eq '2017-08-08T10:20:00+09:0 end ςετίʔυͷվળ: ֎෦ґଘΛແ͘͢
‣ 5%%ϓϩάϥϛϯάதͷઃܭஅͱϑΟʔυόοΫͷؒ ʹ͋ΔΪϟοϓΛೝࣝ͢Δ͜ͱͰ͋ΓɺͦͷΪϟοϓΛί ϯτϩʔϧ͢Δٕ๏Ͱ͋Δɻ ςετۦಈ։ൃೖ ‣ దͳϑΟʔυόοΫΛಘଓ͚ΔΔͨΊʹେࣄͳͷ ‣ Repeatable:
͍࣮ͭߦͯ͠ಉ݁͡ՌʹͳΔ͜ͱ ‣ Independent: ଞͷςετέʔεʹґଘ͠ͳ͍͜ͱ Α͍ςετίʔυͱ
‣ Q1. https://ghe.example.com/moro/emoji_renderer Λ ࣗͷϦϙδτϦͱͯ͠ fork ͠ɺͦΕΛclone͠ͳ͍͞ ‣ Q2. `17day`
ϒϥϯνΛ࡞͠ͳ͍͞ ࣮श
‣ ͜͜·Ͱͷ࣭͕͋Ε࣮श͠ͳ͕ΒखΛ ڍ͍͛ͯͩ͘͞! ࣭ٙλΠϜ
‣ Q3. `hello :innocent:` Λ `hello `ʹม͢Δ ϓϩάϥϜΛTDDͰ࣮͠ͳ͍͞ɻ ‣ 3-1.
ΠϯλʔϑΣʔεΛఆٛ͢ΔͷΈͷࣦഊ͢ΔςετΛ࡞͠ɺίϛοτ͠ͳ͍͞ ‣ 3-2. 3-1ͷςετ͕௨ΔΑ͏ͳԾ࣮ΛՃ͠ɺίϛοτ͠ͳ͍͞ ‣ 3-3. `hello :sunglasses:` Λ `hello ` ʹ͢Δࡾ֯ଌྔͷςετΛՃ͠ɺίϛοτ͠ͳ͍͞ ‣ 3-4. 3-1, 3-3྆ํͷςετ͕௨ΔΑ͏ʹ࣮͠ίϛοτ͠ͳ͍͞ ‣ ώϯτ: "\u{1f607}" "\u{1f60e}" ͰදࣔͰ͖·͢ ‣ ίϛοτϝοηʔδʹʮ3-xʯͷΑ͏ͳ൪߸Λ;͘Ί͍ͯͩ͘͞ɻ ࣮श
‣ Q4. `hello :innocent: :sunglasses:` Λ `hello `ʹ ม͢ΔϓϩάϥϜΛTDDͰ࣮͠ͳ͍͞ɻ ‣
4-1a. ࣗ৴͕͋Δ߹ɺҰؾʹ໌֬ͳ࣮Λ͠ɺίϛοτ͠ͳ͍͞ ‣ 4-1b. ࣗ৴͕ͳ͍߹ɺࣦഊ͢ΔςετɺԾ࣮ɺࡾ֯ଌྔͷςετΛՃ͠ɺίϛοτ͠ͳ͍͞ ࣮श
‣ Q5. gemoji gem Λ͍ɺมίʔυΛϦϑΝΫλϦϯά ͠ͳ͍͞ ‣ https://github.com/github/gemoji ‣ 5-1.
ςετίʔυͷมߋͤͣɺϓϩμΫτίʔυͷΈमਖ਼͠ͳ͍͞ɻ ࣮श
‣ Q6. มίʔυΛ֦ு͠ɺ֦ுUnicodeͰͳ͘ <img>λάΛग़ྗ͢Δ͜ͱʮʯՄೳʹ͠ͳ͍͞ɻ ‣ 期待する出力 "hello <img src=unicode/1f607.png />"
‣ 6-1. ग़ྗΛΓସ͑ΔΠϯλʔϑΣʔεΛઃܭ͠ɺࣦഊ͢ΔςετΛՃ͠ɺίϛοτ͠ͳ͍͞ɻ ‣ 6-2. ϓϩμΫτίʔυΛ࣮͠ɺίϛοτ͠ͳ͍͞ɻ ࣮श
‣ Qn. ୡͰ͖ͨίʔυΛforkͨࣗ͠ϦϙδτϦʹpush͠ɺ moro/emoji_renderer PRΛૹΓͳ͍͞ ‣ descriptionʹͨ͠ײΛॻ͍͍ͯͩ͘͞ ࣮श
͓ർΕ͞·Ͱͨ͠