Upgrade to Pro — share decks privately, control downloads, hide ads and more …

なぜテストを書くの?(または書かないの?) 〜テストコードの7つの役割〜 / #tamarubykaigi01

なぜテストを書くの?(または書かないの?) 〜テストコードの7つの役割〜 / #tamarubykaigi01

Tama Ruby会議01のキーノートとして発表したスライドです。
https://tama-rb.github.io/tamarubykaigi01/

参加レポートはこちら。
https://blog.jnito.com/entry/2019/07/07/102734

Junichi Ito

July 06, 2019
Tweet

More Decks by Junichi Ito

Other Decks in Technology

Transcript

  1. ͳͥςετΛॻ͘ͷʁʢ·ͨ͸ॻ͔ͳ͍ͷʁʣ
    ʙςετίʔυͷ7ͭͷ໾ׂʙ
    ҏ౻ ३Ұ / @jnchito
    2019/07/06 Tama Rubyձٞ01

    View full-size slide

  2. Έͳ͞Μɺςετॻ͍ͯ·͔͢ʁ

    View full-size slide

  3. ςετΛॻ͘ͷ͸޷͖Ͱ͔͢ʁ

    View full-size slide

  4. ςετΛॻ͘ͷ͸ಘҙͰ͔͢ʁ

    View full-size slide

  5. !6
    ͜Μͳਓ͕ࠓ೔ͷର৅ऀͰ͢
    • ςετίʔυ͕ॻ͚ΔΑ͏ʹͳΓ͍ͨʂͰ΋ɺԿΛॻ͚͹͍͍͔Θ͔Βͳ͍
    • RSpecͷجૅ͸ษڧͨ͠ʂͰ΋ɺͲΜͳςετΛॻ͚͹͍͍ͷ͔Θ͔Βͳ͍
    • Ͱɺͦ΋ͦ΋ԿͷͨΊʹςετͬͯॻ͘Μʁ

    View full-size slide

  6. ԿͷͨΊʹςετͬͯॻ͘Μʁ

    View full-size slide

  7. ςετΛॻ͘͜ͱ͕໨తʹͳͬͯͳ͍ʁ

    View full-size slide

  8. !9
    ొஃཪ࿩ɿ๻ͱfuqda͞Μͷ΍ΓͱΓ
    Կ͔ر๬͞ΕΔςʔϚ͸͋Γ·͔͢ʁ
    Qiitaʹॻ͔ΕͨRSpecهࣄͷ૯ूฤతͳ͓࿩Λ
    ͍͖͍ͯͨͩͨ͠Ͱ͢ʂ
    ͳΔ΄Ͳʙɻ
    ʢ৺ͷ੠ʣ
    Ͱ΋ͳʔɺද໘తͳςΫχοΫ͹͔Γڭ͑ͯ΋ͳ͋ɻ
    ͦΕΑΓ΋·ͣɺʮ౔୆ͱͳΔߟ͑ํʯ͸ΈΜͳ͔ͬ͠Γͯ͠ΔΜʁ

    View full-size slide

  9. ͱ͍͏Θ͚Ͱɺ

    View full-size slide

  10. !11
    ࠓ೔͓࿩͢͠Δ͜ͱͱɺࠓ೔ͷΰʔϧ
    • ԿͷͨΊʹςετΛॻ͘ͷ͔ɺͦͷ໨తʢ໾ׂʣΛ7ͭ঺հ͠·͢
    • Ϛον͢Δ໨త͕ͳ͚Ε͹ɺςετ͸ॻ͔ͳ͍͍ͯ͘͠ɺॻ͚ͳ͍͜ͱΛઆ໌͠·͢
    ࠓ೔ͷΰʔϧ
    • ʮςετΛॻ͘͜ͱ͕໨తʯͱ͍͏ঢ়ଶΛଔۀ͢Δ
    • ͳͥࣗ෼͕͍ͭ·Ͱͨͬͯ΋ςετ͕ॻ͚ͳ͍ͷ͔ɺͦͷཧ༝ΛཧղͰ͖ΔΑ͏ʹͳΔ
    ࠓ೔࿩͞ͳ͍͜ͱ
    • ςΫχοΫతͳ࿩ʢRSpecͷ࢖͍ํ౳ʣ͸ࠓ೔ͷςʔϚʹ͸ؚ·Ε·ͤΜ

    View full-size slide

  11. !12
    ʮςετʯͱ͍͏༻ޠʹ͍ͭͯ
    • ݹయతͳఆٛ ʹ ςετͱ͸ɺΤϥʔΛΈ͚ͭΔͭ΋ΓͰϓϩάϥϜΛ࣮ߦ͢Δաఔ
    ‣ ઐ೚ͷςελʔ΍QAΤϯδχΞ͕͍ͨΓ͢Δ͜ͱ΋͋Δ
    ‣ ॻ੶ʮςετۦಈ։ൃʯ෇࿥CΛࢀর
    • ࠓ೔ͷߨԋ ʹ ςετίʔυɺ·ͨ͸ࣗಈςετͷҙຯ
    ‣ ։ൃऀࣗ਎͕ॻ͘
    ‣ ಛʹ஫ऍΛ෇͚ͳ͚Ε͹ɺͬͪ͜ͷҙຯͩͱߟ͍͑ͯͩ͘͞
    • Πϝʔδ͢Δ΋ͷ͕ҟͳΔͱٞ࿦͕͔Έ͋Θͳ͍͜ͱ΋͋ΔͷͰཁ஫ҙ

    View full-size slide

  12. ͱ͜ΖͰɺੲ࿩Λͻͱͭɻ

    View full-size slide

  13. ๻͕ςετΛॻ͖࢝Ί͖͔͚ͨͬ

    View full-size slide

  14. !15
    ॳΊͯͷʮखಈʯςετ
    • 2003೥ SIerʹத్ೖࣾ
    • ౰࣌ͷ֨ݴʮಈ͍͍ͯΔϓϩάϥϜ͸৮Δͳʯ
    • ExcelͰ࡞ͬͨςετ߲໨࢓༷ॻΛݟͳ͕Β໨ࢹͰνΣοΫɺεΫγϣΛషΓ෇͚
    • ϓϩάϥϜΛमਖ਼ͨ͠Βςετ΋΍Γ௚͠
    • ϓϩάϥϜͱҰॹʹςετ݁Ռʢࢴʹҹ࡮ͨ͠΋ͷʣ΋ೲ඼
    • ʮ͏ͪ͸ѱ͘ͳ͍Ͱ͢Αʂ΄Βɺ࢓༷ॻ௨Γʹ࡞Γ·ͨ͠Αʂʯͱݴ͍ுΔͨΊͷςετ

    View full-size slide

  15. !16
    ॳΊͯͷʮࣗಈʯςετ
    • ೖ͔ࣾΒ਺೥ޙɺͱ͋Δ৽ن։ൃҊ݅ͰϨΠϠʔԽΞʔΩςΫνϟ͕࠾༻͞Εͨ
    • ϑϩϯτΤϯυͱόοΫΤϯυͰ׬શʹ෼ۀ͢Δ
    • ϑϩϯτΤϯυ͸APIΛ௨ͯ͡όοΫΤϯυͱ௨৴͢Δ
    • ๻͸όοΫΤϯυνʔϜͷϓϩάϥϚͱͯ͠ࢀՃ
    • ϓϩάϥϜͷςετ݉ɺAPIͷυϥΠόͱͯࣗ͠ಈςετ(JUnit)Λ࠾༻
    • ઌഐϓϩάϥϚͷख΄Ͳ͖Λड͚ͳ͕ΒɺςετίʔυΛ͕Μ͕Μॻ͖·ͬͨ͘

    View full-size slide

  16. ࣗಈςετ͍͢͝ʂָ͍͠ʂ
    Excelํ؟ࢴͳΜͯɺ○Ͷʂʂ

    View full-size slide

  17. !19
    ࣗಈςετΛॳମݧͨ͠๻ͷؾ࣋ͪ
    • ίϚϯυͻͱͭͰςετ͕શ෦΍Γ௚ͤΔʂ
    • ExcelʹεΫγϣΛషΓ෇͚ͳ͍͍ͯ͘ʂΊͬͪΌϥΫʂʂ
    • Կ౓Ͱ΋΍Γ௚ͤΔ͔Βɺίʔυ΋मਖ਼͠์୊ʂ
    • ςετίʔυ΋ҰछͷϓϩάϥϜ͔ͩΒɺॻָ͍͍ͯͯ͠ʂ
    • ख࡞ۀͰςετͳΜͯ΍ͬͯΒΜͶʔɻશ෦ࣗಈԽ͍ͨ͠ʂʂ
    • Ҏདྷɺࣗಈςετେ޷͖ਓؒͱͯ͠ݱࡏʹࢸΔ

    View full-size slide

  18. !20
    ͜͜Ͱͷςετίʔυͷʮ໾ׂʯΛ֬ೝ
    APIΛݺͼग़͢ɺυϥΠόͱͯ͠ͷ໾ׂ
    • UI͕ͳ͍ͷͰɺςετΛॻ͔͟ΔΛಘͳ͍ঢ়گͩͬͨ
    • ςετͷॻ͖ํΛֶͿ্Ͱɺ͜Ε੍͕͍͍໿ʹͳͬͨ
    ࢓༷௨Γʹ࣮૷͞Ε͍ͯΔ͜ͱΛݕূ͢Δ໾ׂ
    • ςετίʔυ͕ςετ࢓༷ॻ୅ΘΓʹͳͬͨʢΑ͏ͳؾ͕͢Δʣ
    ϦϑΝΫλϦϯάͯ͠΋ϓϩάϥϜ͕յΕ͍ͯͳ͍͜ͱΛূ໌͢Δ໾ׂ
    • ʮಈ͍͍ͯΔϓϩάϥϜ͸৮Δͳʯϧʔϧ͔Βͷղ์

    View full-size slide

  19. ຊ୊ɿςετίʔυͷ໾ׂͱ͸Կ͔ʁ

    View full-size slide

  20. !22
    ΠϯτϩμΫγϣϯ
    • ࣗಈςετେ޷͖ਓؒͱͯ͠ςετίʔυΛॻ͖ଓ͚͖ͯͨ๻
    • ςετΛॻ͘ཧ༝Λߟ͑ͯΈΔͱɺ͍͔ͭ͘ͷ໾ׂʢύλʔϯʣ͕͋Δ͜ͱʹؾͮ͘
    • ͦͷ໾ׂΛ7ͭɺ͜Ε͔Β঺հ͍͖ͯ͠·͢

    View full-size slide

  21. • ๻͕ࠓಇ͍͍ͯΔιχοΫΨʔσϯͰॻ͍͍ͯΔςετίʔυΛ૝ఆ͍ͯ͠·͢
    • ۩ମతʹ͸ҎԼͷΑ͏ͳ؀ڥͰ͢
    ‣ ि୯ҐͰސ٬ͱϛʔςΟϯάΛ։͍ͯ։ൃͱϦϦʔεΛ܁Γฦ͢
    ‣ 1Ҋ݅͋ͨΓͷ։ൃϝϯόʔ͸গ਺
    ‣ ϦϦʔεલͷPull Request͸ίʔυϨϏϡʔ͕ඞਢ
    ‣ ܰඍͳෆ۩߹Ͱ͋Ε͹։ൃऀ͕͙͢ʹमਖ਼ͯ͠ϦϦʔεՄೳ
    ‣ RailsͱRSpecΛ࢖ͬͨWebΞϓϦ։ൃͱࣗಈςετ͕ϝΠϯ
    !23
    લఏ৚݅

    View full-size slide

  22. !24
    ͜Ε͔Β঺հ͢Δ7ͭͷ໾ׂ
    1. ҆શωοτͱͯ͠ͷ໾ׂ
    2. ࣮૷ͷਖ਼͠͞Λূ໌͢Δ໾ׂ
    3. ίʔυͷ඼࣭Λ޲্ͤ͞Δ໾ׂ
    4. লྗԽπʔϧͱͯ͠ͷ໾ׂ
    5. όάΛୟ͖௵͢໾ׂ
    6. ઃܭΛࢧԉ͢Δ໾ׂ
    7. આ໌ॻͱͯ͠ͷ໾ׂ

    View full-size slide

  23. 1. ҆શωοτͱͯ͠ͷ໾ׂ

    View full-size slide

  24. !26
    1. ҆શωοτͱͯ͠ͷ໾ׂ
    • ςετίʔυ͸ΞϓϦέʔγϣϯͷ҆શωοτɺ໋ߝɺ๷஄νϣοΩ
    • ػೳΛ௥Ճɾมߋͯ͠΋ɺଞͷ෦෼͕յΕ͍ͯͳ͍͜ͱΛอূ͢Δ
    • Ruby΍RailsɺgemΛΞοϓσʔτͯ͠΋յΕ͍ͯͳ͍͜ͱΛอূ͢Δ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • େن໛ͳϓϩάϥϜΛຖճख࡞ۀͰ࠶ςετ͢Δͷ͸ඇݱ࣮త͔ͩΒ
    • ϓϩάϥϜ͕յΕΔͱސ٬΍ར༻ऀʹ໎࿭ֻ͕͔Δ͔Β
    • ࠓޙ΋௕͘ӡ༻͞ΕΔݟࠐΈ͕ߴ͍͔Β

    View full-size slide

  25. !27
    ͜Ε͚ͩͰಈ࡞֬ೝ͕ऴΘΔͳΜͯ࠷ߴʂ
    $ bin/rspec
    Finished in 5.31 seconds (files took 2.24 seconds to load)
    70 examples, 0 failures
    $ bundle update rails
    Bundle updated!
    $ bin/rspec
    Finished in 3.91 seconds (files took 0.50523 seconds to load)
    70 examples, 0 failures

    View full-size slide

  26. 2. ࣮૷ͷਖ਼͠͞Λূ໌͢Δ໾ׂ

    View full-size slide

  27. !29
    2. ࣮૷ͷਖ਼͠͞Λূ໌͢Δ໾ׂ
    • ࣮૷ͨ͠ίʔυ͕ཁ݅Λຬ͍ͨͯ͠Δ͜ͱ΍ɺ࢓༷௨Γʹಈ͘͜ͱΛݕূ͢Δ
    • ςετ͕ύε͢Ε͹ɺࣗ৴Λ࣋ͬͯϦϦʔε͢Δ͜ͱ͕Ͱ͖Δ
    ‣ ͨͩ͠ɺςετ߲໨ʹψέϞϨ͕ͳ͘ɺ࣮֬ʹҟৗΛݕ஌Ͱ͖ΔςετͰ͋Δ͜ͱ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • ސ٬΍ར༻ऀʹରͯ͠ෆ۩߹͕ͳ͍͜ͱΛ୲อ͢Δඞཁ͕͋Δ͔Β
    • ਓؒͱҧͬͯࣗಈςετ͸ർΕͨΓɺݟؒҧ͍Λͨ͠Γ͠ͳ͍͔Β

    View full-size slide

  28. !30
    ྫɿ13ܻͷISBNΛ10ܻʹม׵͢ΔϓϩάϥϜΛςετ͢Δ
    require './lib/isbn_converter'
    require 'rspec'
    RSpec.describe 'isbn_converter' do
    describe '#convert_isbn' do
    example '13ܻͷISBNΛ10ܻʹม׵Ͱ͖Δ' do
    expect(convert_isbn('9784774193977')).to eq '4774193976'
    end
    example 'νΣοΫσΟδοτ͕10ʹͳΔͱ͖͸XͰऴΘΔ' do
    expect(convert_isbn('9784774183619')).to eq '477418361X'
    end
    end
    end
    ࠷ޙͷ1ܻ͕νΣοΫσΟδοτ
    in 13ܻ out 10ܻ

    View full-size slide

  29. 3. ίʔυͷ඼࣭Λ޲্ͤ͞Δ໾ׂ

    View full-size slide

  30. !32
    3. ίʔυͷ඼࣭Λ޲্ͤ͞Δ໾ׂ
    • ςετίʔυ͕͋Ε͹ࣗ৴Λ΋ͬͯϦϑΝΫλϦϯά͕Ͱ͖Δ
    • ίʔυϨϏϡʔͷࢦఠࣄ߲Λमਖ਼͢Δʹ͸ɺςετίʔυ͕ඞਢ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • ίʔυͷՄಡੑ΍อकੑ͕ߴ͚Ε͹ߴ͍΄Ͳɺকདྷͷ։ൃ޻਺Λ୹ॖͰ͖Δ͔Β
    • ଞͷϝϯόʔ΍কདྷͷࣗ෼ͷɺਫ਼ਆతετϨεΛܰݮͰ͖Δ͔Β

    View full-size slide

  31. !33
    ྫɿRGBม׵ϓϩάϥϜͷϦϑΝΫλϦϯά
    def to_ints(hex)
    r = hex[1..2]
    g = hex[3..4]
    b = hex[5..6]
    ints = []
    [r, g, b].each do |s|
    ints << s.hex
    end
    ints
    end
    def to_ints(hex)
    hex.scan(/\w\w/).map(&:hex)
    end
    class RgbTest < Minitest::Test
    def test_to_ints
    assert_equal [0, 0, 0], to_ints('#000000')
    assert_equal [255, 255, 255], to_ints('#ffffff')
    assert_equal [4, 60, 120], to_ints('#043c78')
    end
    end
    16ਐ਺ͷ৭ίʔυΛ10ਐ਺ʹม׵Ͱ͖Δ͜ͱΛݕূ
    ϦϑΝΫλϦϯάલ
    ϦϑΝΫλϦϯάޙ ✨
    in 16ਐ਺
    out 10ਐ਺

    View full-size slide

  32. 4. লྗԽπʔϧͱͯ͠ͷ໾ׂ

    View full-size slide

  33. !35
    4. লྗԽπʔϧͱͯ͠ͷ໾ׂ
    • खͱ໨Ͱ܁Γฦ֬͠ೝ͢Δͷ͸ख͕͔͔ؒΔͷͰɺࣗಈԽͯ͠։ൃ޻਺Λ୹ॖ͢Δ
    • ։ൃ؀ڥͷߏங͕େมͳͷͰɺςετίʔυ্͚ͩͰখ͞ͳ࢓༷มߋΛࡁ·ͤΔ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • શ෦ख࡞ۀͰಈ࡞֬ೝ͢ΔΑΓ΋ɺࣗಈԽͨ͠ํ͕࠷ऴతͳඅ༻ରޮՌ͕ߴ͍͔Β
    • ςετίʔυ͕͋Ε͹ɺଞͷ։ൃऀʹυϩοϓΠϯͰߩݙͯ͠΋Β͍΍͘͢ͳΔ͔Β

    View full-size slide

  34. !36
    ྫɿϢʔβʔొ࿥ޙͷ௨஌ϝʔϧૹ৴Λςετ͢Δ
    RSpec.describe 'Users', type: :system do
    describe 'Sign up' do
    example 'Ϣʔβʔొ࿥͢ΔͱWelcomeϝʔϧ͕ૹ৴͞ΕΔ' do
    visit new_user_registration_path
    fill_in 'Eϝʔϧ', with: '[email protected]'
    fill_in 'ύεϫʔυ', with: 'password'
    expect { click_button 'ొ࿥͢Δ' }.to \
    change(ActionMailer::Base.deliveries, :count).by(1)
    end
    end
    end
    ᶃ Ϣʔβʔొ࿥ը໘Λ։͘
    ᶄ ϝΞυͱύεϫʔυΛೖྗ
    ᶅ ొ࿥͕׬ྃͨ͠Β௨஌ϝʔϧ͕ૹ৴͞ΕΔ͜ͱΛ֬ೝ

    View full-size slide

  35. 5. όάΛୟ͖௵͢໾ׂ

    View full-size slide

  36. !38
    5. όάΛୟ͖௵͢໾ׂ
    • ෆ۩߹͕ൃੜͨ͠ΒɺίʔυΛमਖ਼͢ΔલʹςετΛॻ͘
    • ςετ͕མͪΔ͜ͱΛ֬ೝͨ͠Βɺςετ͕ύε͢ΔΑ͏ʹίʔυΛमਖ਼͢Δ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • ςετίʔυΛॻ͘͜ͱʹΑΓɺෆ۩߹ͷ࠶ൃΛ๷ࢭͰ͖Δ͔Β
    • ಉ͡ෆ۩߹ΛԿ౓΋࠶ൃͤ͞Δͱɺސ٬΍ར༻ऀͷ৴པΛࣦ͏͔Β
    • ݪҼͷڀ໌΍ίʔυͷमਖ਼͕େมͩͬͨ৔߹ɺࢼߦࡨޡΛ܁Γฦ͠΍͍͔͢Β

    View full-size slide

  37. !39
    ྫɿϢʔβʔݕࡧ࣌ͷෆ۩߹ΛςετΛॻ͍͔ͯΒमਖ਼͢Δ
    RSpec.describe 'Users', type: :system do
    let!(:user) { create :user, email: '[email protected]', name: 'ҏ౻३Ұ' }
    describe 'Ϣʔβʔͷݕࡧ' do
    example 'Eϝʔϧͷେจࣈɾখจࣈ͸ແࢹͯ͠ݕࡧ͢Δ' do
    visit users_path
    fill_in 'Eϝʔϧ', with: '[email protected]'
    click_button 'ݕࡧ͢Δ'
    expect(page).to have_content 'ҏ౻३Ұ'
    end
    end
    end
    ↑ मਖ਼લ͸User͕ݟ͔ͭΒͣɺ͜͜Ͱςετ͕ࣦഊ͢Δ
    খจࣈͰొ࿥
    େจࣈͰݕࡧ

    View full-size slide

  38. !40
    ྫɿϢʔβʔݕࡧ࣌ͷෆ۩߹ΛςετΛॻ͍͔ͯΒमਖ਼͢Δ
    RSpec.describe 'Users', type: :system do
    let!(:user) { create :user, email: '[email protected]', name: 'ҏ౻३Ұ' }
    describe 'Ϣʔβʔͷݕࡧ' do
    example 'Eϝʔϧͷେจࣈɾখจࣈ͸ແࢹͯ͠ݕࡧ͢Δ' do
    visit users_path
    fill_in 'Eϝʔϧ', with: '[email protected]'
    click_button 'ݕࡧ͢Δ'
    expect(page).to have_content 'ҏ౻३Ұ'
    end
    end
    end
    খจࣈͰొ࿥
    େจࣈͰݕࡧ
    ↑ ͪΌΜͱमਖ਼Ͱ͖ͨΒςετ͕ύε͢Δ

    View full-size slide

  39. 6. ઃܭΛࢧԉ͢Δ໾ׂ

    View full-size slide

  40. !42
    6. ઃܭΛࢧԉ͢Δ໾ׂ
    • ࣮૷͢ΔલʹςετίʔυΛॻ͖࢝ΊΔͱɺϓϩάϥϜͷઃܭʹ໾ཱͭ
    ‣ ϝιου໊΍Ҿ਺ɺ໭Γ஋ɺςετύλʔϯͳͲΛςετίʔυ্Ͱݕ౼Ͱ͖Δ
    ‣ ͍ΘΏΔʮςετϑΝʔετʯͷख๏
    • ͞Βʹ͔ͦ͜Βର࿩తʹ࣮૷ΛਐΊΔ͜ͱ͕Ͱ͖Δ
    ‣ ઌʹ͍͔ͭ͘ͷςετέʔεΛॻ͍͓͖ͯɺॱʹάϦʔϯʹ͍ͯ͘͠
    ͳͥςετΛॻ͘ͷ͔ʁ
    • ࣮ࡍʹͦͷϓϩάϥϜΛར༻͢ΔίʔυΛॻ͘͜ͱͰɺઃܭͷྑ͠ѱ͠ʹؾ͚ͮΔ͔Β

    View full-size slide

  41. !43
    ྫɿࣗಈൢചػϓϩάϥϜΛςετ͔Βઌʹॻ͍ͯΈΔ
    RSpec.describe VendingMachine do
    example '͓ۚͷ౤ೖͱ෷͍໭͠' do
    end
    end ※ʮTDDBCେࡕ3.0/՝୊ʯΛࢀߟʹ࡞੒
    • ϝιου໊͸Θ͔Γ΍͍͔͢ʁ
    • Ҿ਺΍໭Γ஋͸͜ΕͰ͍͍͔ʁ
    • ͓ۚΛද͢Ϋϥε΋࡞Δ΂͖͔ʁ etc
    machine = VendingMachine.new
    # 10ԁۄɺ100ԁۄΛ̍ͭͣͭ౤ೖͰ͖Δɻ౤ೖ͸ෳ਺ճͰ͖Δɻ
    machine.insert 10
    machine.insert 10
    machine.insert 100
    # ౤ೖֹۚͷ૯ܭΛऔಘͰ͖Δɻ
    expect(machine.money_sum).to eq 120
    # ෷͍໭͠ૢ࡞Λߦ͏ͱɺ౤ೖֹۚͷ૯ܭΛ௼Γમͱͯ͠ग़ྗ͢Δɻ
    expect(machine.return_money).to contain_exactly(10, 10, 100)
    expect(machine.money_sum).to eq 0
    ݕ౼Ͱ͖ͨΒ࣮૷։࢝ʂ

    View full-size slide

  42. 7. આ໌ॻͱͯ͠ͷ໾ׂ

    View full-size slide

  43. !45
    7. આ໌ॻͱͯ͠ͷ໾ׂ
    • ςετίʔυΛಡΊ͹ɺϓϩάϥϜͷ࢓༷΍σʔλߏ଄͕೺ѲͰ͖Δ
    • ౷߹ςετʢfeature spec / system specʣΛݟΕ͹ɺը໘ͷૢ࡞ํ๏͕Θ͔Δ
    • gemͷ࢖͍ํ΍Rubyͷ৽ػೳ΋ɺςετΛಡΜͩํ͕෼͔Γ΍͍͢͜ͱ͕͋Δ
    ͳͥςετΛॻ͘ͷ͔ʁ
    • ଞͷϝϯόʔ΍কདྷͷࣗ෼͕ɺϓϩάϥϜΛཧղ͠΍͘͢ͳΔ͔Β
    • ಡΉ͚ͩͰͳ͘ɺಈ͔ͯ֬͠ೝ͢Δ͜ͱ΋Ͱ͖Δ͔Β

    View full-size slide

  44. !46
    ྫɿliberal_parsingΦϓγϣϯͬͯԿʁ
    def test_liberal_parsing
    input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
    assert_raise(CSV::MalformedCSVError) do
    CSV.parse_line(input)
    end
    assert_equal(["Johnson, Dwayne", 'Dwayne "The Rock" Johnson'],
    CSV.parse_line(input, liberal_parsing: true))
    Ͳ͏΍ΒɺมͳCSVςΩετ΋
    ͍͍ײ͡ʹύʔεͯ͘͠ΕΔͬΆ͍ʂ
    NEWS for Ruby 2.4.0
    CSV
    • Add a liberal_parsing option. [Feature #11839]

    ← มͳCSVςΩετ
    ⚠ ;ͭ͏ʹύʔε͢ΔͱΤϥʔ
    https://github.com/ruby/ruby/blob/trunk/test/csv/test_features.rb ΑΓൈਮ

    View full-size slide

  45. ͳͥςετΛॻ͘ͷʁ
    ͳͥςετΛॻ͔ͳ͍ͷʁ
    ʢ·ͨ͸ॻ͚ͳ͍ͷʁʣ
    VS

    View full-size slide

  46. !48
    ͓͞Β͍ɿͳͥςετΛॻ͘ͷ͔ʁʢൈਮʣ
    • େن໛ͳϓϩάϥϜΛຖճख࡞ۀͰ࠶ςετ͢Δͷ͸ඇݱ࣮త͔ͩΒ
    • ࠓޙ΋௕͘ӡ༻͞ΕΔݟࠐΈ͕ߴ͍͔Β
    • ϓϩάϥϜ͕յΕΔͱސ٬΍ར༻ऀʹ໎࿭ֻ͕͔Δ͔Β
    • ίʔυͷՄಡੑ΍อकੑ͕ߴ͚Ε͹ߴ͍΄Ͳɺকདྷͷ։ൃ޻਺Λ୹ॖͰ͖Δ͔Β
    • શ෦ख࡞ۀͰಈ࡞֬ೝ͢ΔΑΓ΋ɺࣗಈԽͨ͠ํ͕࠷ऴతͳඅ༻ରޮՌ͕ߴ͍͔Β

    View full-size slide

  47. ཧ༝Λͻͬ͘Γฦͯ͠ΈΔͱɾɾɾ

    View full-size slide

  48. !50
    ͳͥςετΛॻ͔ͳ͍ͷ͔ʁʢॻ͚ͳ͍ͷ͔ʁʣ
    • ख࡞ۀͰ΋ͳΜͱ͔࠶ςετͰ͖Δখن໛ͳϓϩάϥϜ͔ͩΒ
    • ͙͢ʹ࢖Θͳ͘ͳΔ͔Β
    • ϓϩάϥϜ͕յΕͯ΋ಛʹ୭ʹ΋໎࿭ֻ͕͔Βͳ͍͔Β
    • ࣗ෼ҰਓͰ։ൃ͢Δ্Ͱ͸ɺଟগԚͯ͘΋ίʔυΛཧղͰ͖Δ͔Β
    • ೲظ΍޻਺Λؾʹͤͣɺ͍͘ΒͰ΋ख࡞ۀͰಈ࡞֬ೝͰ͖Δ͔Β

    View full-size slide

  49. !51
    ࣗ෼ͷࠓͷঢ়گΛ֬ೝͯ͠ΈΑ͏
    • େن໛ʢखಈςετ͕ඇݱ࣮తͳϨϕϧʣ
    • ण໋͕௕͍
    • ސ٬΍ར༻ऀʹରͯ͠੹೚Λෛ͍ͬͯΔ
    • ଞͷ։ൃऀ͕͍Δ
    • ༩͑ΒΕͨ޻਺͕ݶΒΕ͍ͯΔ
    • ͘͝খن໛
    • ण໋͕୹͍
    • ੹೚Λෛ͏΂͖ސ٬΍ར༻ऀ͕͍ͳ͍
    • ̍ਓͰ։ൃ͍ͯ͠Δ
    • ޻਺͸ແݶʹ࢖͑Δ
    ࣗಈςετ͕ෆՄܽ ࣗಈςετͷඞཁੑ͕ݶఆత
    ࢓ࣄͱͯ͠ίʔυΛॻ͘ਓ͸ͬͪ͜ʁ ಠֶͰษڧͯ͠Δਓ͸ͬͪ͜ʁ

    View full-size slide

  50. ͦΕͰ΋ॻ͚ͳ͍ʂͱ͍͏ਓʹૹΔ
    6ͭͷॲํᝦ

    View full-size slide

  51. !53
    ͦΕͰ΋ॻ͚ͳ͍ʂͱ͍͏ਓʹૹΔɺ6ͭͷॲํᝦ
    1. ༏ઌॱҐΛ෇͚ͯ·͔͢ʁ
    • ʮ͕͜͜յΕ͍ͯΔͱக໋తʯͱ͍͏ཁ͔݅ΒςετΛݻΊ͍ͯ͜͏
    • αʔϏεͷओ࣠ͱͳΔϢʔεέʔεɺ՝ۚपΓɺݖݶपΓɺetc
    2. ςετ͠΍͍͢ઃܭɾσʔλߏ଄ʹͳ͍ͬͯ·͔͢ʁ
    • RailsͷϨʔϧʹ৐ͬͨίʔυΛॻ͜͏
    • ΦϒδΣΫτͷ੹຿Λద੾ʹ෼ׂ͠Α͏
    • ʮΦϒδΣΫτࢦ޲ઃܭ࣮ફΨΠυʯ౳ͷॻ੶ΛಡΜͰΈΔ

    View full-size slide

  52. !54
    ͦΕͰ΋ॻ͚ͳ͍ʂͱ͍͏ਓʹૹΔɺ6ͭͷॲํᝦ
    3. צͱܦݧ͚ͩͰςετ߲໨ΛܾΊ͍ͯ·ͤΜ͔ʁ
    • ମܥతͳςετٕ๏ΛֶΜͰɺψέϞϨͷͳ͍ɺ࠷গɾ࠷ળͷςετ߲໨Λ༻ҙ͠Α͏
    • ʮ͸͡ΊֶͯͿιϑτ΢ΣΞͷςετٕ๏ʯ౳ͷॻ੶ΛಡΜͰΈΔ
    4. πʔϧͷ࢖͍ํ΍ࣗಈԽͷςΫχοΫ͸शಘ͍ͯ͠·͔͢ʁ
    • ۩ମతͰ࣮ફతͳϊ΢ϋ΢Λֶ΅͏
    • ʮEveryday Rails - RSpecʹΑΔRailsςετೖ໳ʯΛಡΜͰΈΔ

    View full-size slide

  53. !55
    ͦΕͰ΋ॻ͚ͳ͍ʂͱ͍͏ਓʹૹΔɺ6ͭͷॲํᝦ
    5. ڭ৚తɺ·ͨ͸ݪཧओٛతͳϧʔϧʹัΒΘΕ͍͗ͯ͢·ͤΜ͔ʁ
    • ςετϑΝʔετ͕ඞਢɺRSpecͷsubject͕ඞਢɺitͷதͷexpect͸ඞͣ1ͭɺetc
    • ໨త΍໾ׂΛຬͨ͢ͳΒɺ͋Δఔ౓ʮࡶʯͳςετίʔυ΋ڐ༰͠Α͏
    6. ͪΌΜͱɺ΋͕͖ۤ͠ΜͰ·͔͢ʁࢼߦࡨޡ͠·ͬͯ͘·͔͢ʁ
    • πʔϧͷΫη΍ɺΑ͋͘Δམͱ݀͠ʹϋϚΔ͜ͱ͸ɺ͋Β͔͡Ί֮ޛ͓ͯ͜͠͏
    • ࣗಈςετͷशಘʹ͸͕͔͔࣌ؒΔ΋ͷͰ͢ɻͨ͘͞ΜςετΛॻ͜͏ʂʂ

    View full-size slide

  54. !57
    ͓͞Β͍ɿࠓ೔͓࿩͢͠Δ͜ͱͱɺࠓ೔ͷΰʔϧ
    • ԿͷͨΊʹςετΛॻ͘ͷ͔ɺͦͷ໨తʢ໾ׂʣΛ7ͭ঺հ͠·͢
    • Ϛον͢Δ໨త͕ͳ͚Ε͹ɺςετ͸ॻ͔ͳ͍͍ͯ͘͠ɺॻ͚ͳ͍͜ͱΛઆ໌͠·͢
    ࠓ೔ͷΰʔϧ
    • ʮςετΛॻ͘͜ͱ͕໨తʯͱ͍͏ঢ়ଶΛଔۀ͢Δ
    • ͳͥࣗ෼͕͍ͭ·Ͱͨͬͯ΋ςετ͕ॻ͚ͳ͍ͷ͔ɺͦͷཧ༝ΛཧղͰ͖ΔΑ͏ʹͳΔ
    ࠓ೔࿩͞ͳ͍͜ͱ
    • ςΫχοΫతͳ࿩ʢRSpecͷ࢖͍ํ౳ʣ͸ࠓ೔ͷςʔϚʹ͸ؚ·Ε·ͤΜ

    View full-size slide

  55. !58
    ςετίʔυͷ7ͭͷ໾ׂ
    1. ҆શωοτͱͯ͠ͷ໾ׂ
    2. ࣮૷ͷਖ਼͠͞Λূ໌͢Δ໾ׂ
    3. ίʔυͷ඼࣭Λ޲্ͤ͞Δ໾ׂ
    4. লྗԽπʔϧͱͯ͠ͷ໾ׂ
    5. όάΛୟ͖௵͢໾ׂ
    6. ઃܭΛࢧԉ͢Δ໾ׂ
    7. આ໌ॻͱͯ͠ͷ໾ׂ
    Ͳͷ໾ׂʢͲͷ໨తʣͰࣗ෼͸
    ςετΛॻ͜͏ͱ͍ͯ͠Δͷ͔ɺ
    ࣗ໰ࣗ౴ͯ͠ΈΑ͏

    View full-size slide

  56. !59
    ࣗ෼ͷࠓͷঢ়گΛ֬ೝͯ͠ΈΑ͏
    • େن໛ʢखಈςετ͕ඇݱ࣮తͳϨϕϧʣ
    • ण໋͕௕͍
    • ސ٬΍ར༻ऀʹରͯ͠੹೚Λෛ͍ͬͯΔ
    • ଞͷ։ൃऀ͕͍Δ
    • ༩͑ΒΕͨ޻਺͕ݶΒΕ͍ͯΔ
    • ͘͝খن໛
    • ण໋͕୹͍
    • ੹೚Λෛ͏΂͖ސ٬΍ར༻ऀ͕͍ͳ͍
    • ̍ਓͰ։ൃ͍ͯ͠Δ
    • ޻਺͸ແݶʹ࢖͑Δ
    ࣗಈςετ͕ෆՄܽ ࣗಈςετͷඞཁੑ͕ݶఆత
    ςετແ͠͡Όɺ΍͍ͬͯΒΕͳ͍ঢ়گ ςετΛॻ͘ಈػ͕ੜ·Εʹ͍͘ঢ়گ

    View full-size slide

  57. !60
    ͦΕͰ΋ॻ͚ͳ͍ʂͱ͍͏ਓʹૹΔɺ6ͭͷॲํᝦ
    1. ༏ઌॱҐΛ෇͚ͯ·͔͢ʁ
    2. ςετ͠΍͍͢ઃܭɾσʔλߏ଄ʹͳ͍ͬͯ·͔͢ʁ
    3. צͱܦݧ͚ͩͰςετ߲໨ΛܾΊ͍ͯ·ͤΜ͔ʁ
    4. πʔϧͷ࢖͍ํ΍ࣗಈԽͷςΫχοΫ͸शಘ͍ͯ͠·͔͢ʁ
    5. ڭ৚తɺ·ͨ͸ݪཧओٛతͳϧʔϧʹัΒΘΕ͍͗ͯ͢·ͤΜ͔ʁ
    6. ͪΌΜͱɺ΋͕͖ۤ͠ΜͰ·͔͢ʁࢼߦࡨޡ͠·ͬͯ͘·͔͢ʁ
    ⚠ ΈΜͳ͚ͩ͜͜ʹ஫໨͕ͪ͠

    View full-size slide

  58. ͪΌΜͱɺ΋͕͖ۤ͠ΜͰ·͔͢ʁ
    ࢼߦࡨޡ͠·ͬͯ͘·͔͢ʁ

    View full-size slide

  59. Tama Rubyձٞ01ͷςʔϚ͸
    ʮRubyistͱͯ͠ͷ੒௕ʯ

    View full-size slide

  60. ੒௕ʹ͸͕͔͔࣌ؒΔ΋ͷͰ͢
    Image https://flic.kr/p/2efYM7y

    View full-size slide

  61. ৼΓฦΔͱɺͪΐͬͱ͍ۤ͠ܦݧͷํ͕
    ࣗ෼ͷ੒௕ʹͭͳ͕Γ΍͔ͬͨ͢
    Image https://flic.kr/p/784S5m

    View full-size slide

  62. ͜ͷߨԋΛฉ͍͔ͯۤͬͨ͠Ͱ͔͢ʁ

    View full-size slide

  63. ۤ͘͠ͳ͍Ͱ͢ΑͶ

    View full-size slide

  64. ͭ·ΓɺߨԋΛฉ͚ͩ͘Ͱ͸
    ʮ·ͩʯ੒௕Ͱ͖·ͤΜ

    View full-size slide

  65. ͜ͷΠϕϯτ͕ऴΘͬͨΒ
    ·ͨటष͘ίʔυΛॻ͍͍͖ͯ·͠ΐ͏
    Image https://flic.kr/p/55ucdV

    View full-size slide

  66. ࠓ೔ͷߨԋ͕Έͳ͞Μͷʮ੒௕ʯʹ
    ໾ཱͯ͹޾͍Ͱ͢
    Image https://flic.kr/p/fdn2U7

    View full-size slide

  67. ɹɹɹ͋Γ͕ͱ͏͍͟͝·ͨ͠
    !KODIJUP
    CMPHKOJUPDPN
    ͝੒௕

    View full-size slide

  68. ͝੩ௌ
    ɹɹɹ͋Γ͕ͱ͏͍͟͝·ͨ͠
    !KODIJUP
    CMPHKOJUPDPN

    View full-size slide