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
nekko cloudにおけるProxmox VE利用事例
irumaru
3
390
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
170
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
170
社内活動の取り組み紹介 ~ スリーシェイクでこんな取り組みしてます ~
bells17
0
400
CSC509 Lecture 14
javiergs
PRO
0
130
Security_for_introducing_eBPF
kentatada
0
110
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
7.7k
fs2-io を試してたらバグを見つけて直した話
chencmd
0
190
layerx_20241129.pdf
kyoheig3
2
280
暇に任せてProxmoxコンソール 作ってみました
karugamo
1
690
Refactor your code - refactor yourself
xosofox
1
230
Criando Commits Incríveis no Git
marcelgsantos
2
160
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Music & Morning Musume
bryan
46
6.2k
Optimising Largest Contentful Paint
csswizardry
33
3k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
The Language of Interfaces
destraynor
154
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
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ʹͨ͠ײΛॻ͍͍ͯͩ͘͞ ࣮श
͓ർΕ͞·Ͱͨ͠