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

RSpecはじめました

kkabetani
October 19, 2013

 RSpecはじめました

kanazawa.rb meetup #14 で行われたミニコーナー「Test ! Test !! Test !!!」で発表したスライド

kkabetani

October 19, 2013
Tweet

More Decks by kkabetani

Other Decks in Programming

Transcript

  1. 34QFD͸͡Ί·ͨ͠

    LBOB[BXBSCNFFUVQ
    !LLBCFUBOJ

    View full-size slide

  2. ࣗݾ঺հ
    w!LLBCFUBOJ
    w5PZBNB
    w+BWBͰ8FCΞϓϦ࡞ͬͯ·͢
    w+BWB4DSJQUগʑ
    w3VCZ͸झຯͰ৮ͬͯ·͢

    View full-size slide

  3. ̏ϲ݄લ
    wʮͨͷ͍͠3VCZʯΛࣸܦͨ͠
    w3VCZPO3BJMT΍ͬͯΈΑ͏͔ͳʔ
    wLBOB[BXBSCʹॳࢀՃͨ͠

    View full-size slide

  4. 34QFDͬͯԿʁ

    View full-size slide

  5. ࠷ۙ
    w3VCZPO3BJMTͰΞϓϦ࡞͔ͬͨΒςε
    τॻ͜͏ʢ࣍͸5%%Ͱ΍ͬͯΈΑ͏ʣ
    w(FN࡞ͬͯΈΑ͏
    w%4-ʁԿͦΕʁ໘നͦ͏
    wLBOB[BXBSCʹࢀՃָͯ͘͠͠ͳͬͯ
    ͖ͨ

    View full-size slide

  6. 34QFDͪΐͬͱ
    ෼͔͖ͬͯͨ

    View full-size slide

  7. ͦΜͳࣗ෼͕
    34QFDͰษڧ͖ͯ͠
    ͨ͜ͱΛൃද͠·͢

    View full-size slide

  8. 34QFDͱͷग़ձ͍
    w3VCZPO3BJMTνϡʔτϦΞϧͰࣸ
    ܦͯ͠ษڧͯͨ͠ͱ͖ 3BJMTW

    wIUUQSBJMTUVUPSJBMKQ

    View full-size slide

  9. ࠷ॳʹॻ͍ͨ34QFD
    require 'spec_helper'
    describe "Static pages" do
    describe "Home page" do
    it "should have the content 'Sample App'" do
    visit '/static_pages/home'
    page.should have_content('Sample App')
    end
    end
    end

    View full-size slide

  10. ࠷ॳʹॻ͍ͨ34QFD
    require 'spec_helper'
    describe "Static pages" do
    describe "Home page" do
    it "should have the content 'Sample App'" do
    visit '/static_pages/home'
    page.should have_content('Sample App')
    end
    end
    end

    View full-size slide

  11. ࠷ॳʹॻ͍ͨ34QFD
    require 'spec_helper'
    describe "Static pages" do
    describe "Home page" do
    it "should have the content 'Sample App'" do
    visit '/static_pages/home'
    page.should have_content('Sample App')
    end
    end
    end

    View full-size slide

  12. ϯʁφχίϨʁ
    w3VCZͬΆ͍͚Ͳ
    w͜Μͳͷशͬͯͳ͍Μ͚ͩͲ
    wEFTDSJCF
    wJU
    wϒϩοΫʁ

    View full-size slide

  13. ࠷ॳ͸ͱʹ͔ࣸ͘ܦ͠
    ͯಈ͖ΛݟͯΔ͚ͩ

    View full-size slide

  14. ࣦഊͯ͠ΔͶ

    View full-size slide

  15. ·ͨࣸܦͯ͠࠶࣮ߦ

    View full-size slide

  16. ࣸܦΛ܁Γฦͨ݁͠Ռ
    wগͮͭ͠34QFDͷ֓ཁ͕෼͔͖ͬͯͨ
    wSBJMTͷಈ͖Λॻ͍ͯςετͯ͠Δͩͳ

    View full-size slide

  17. ٙ໰΋ͨ͘͞Μग़͖ͯͨ

    View full-size slide

  18. ٙ໰
    wͰ΋ɺ͜ΕͲ͏͍͏ಈ͖ʹͳͬͯΔ
    ͷʁ
    w3VCZͳͷʁ
    wEFTDSJCFͱ͔JUͱ͔·ͩΑ͘෼͔ͬ
    ͯͳ͍Μ͚ͩͲ

    View full-size slide

  19. LBOB[BXBSC
    w!:VLJNJUTV@*[BXB͞Μͷൃද
    w3VCZͰ࡞Δ%4-
    wIUUQXXXTMJEFTIBSFOFU
    ZJ[BXBSVCZETM

    View full-size slide

  20. LBOB[BXBSC
    w34QFD͸3VCZͰ࣮૷͞Εͨ಺෦
    %4-
    w؆୯ͳίʔυͰ%4-Λઆ໌͍ͯͨͩ͠
    ͘

    View full-size slide

  21. ͋ʂ34QFD΋ϒϩο
    Ϋ౉ͯ͠Δͷ͔΋

    View full-size slide

  22. 3VCZPO3BJMT͸
    ͪΐͬͱஔ͍ͱ͍ͯɺ
    34QFD %4-
    ͷษڧ͠
    ͯΈΑ͏

    View full-size slide

  23. 34QFDͱ͸Կ͔ʁ
    wϓϩάϥϜͷৼ෣ CFIBWJPVS
    Λه
    ड़͢ΔͨΊͷυϝΠϯಛԽݴޠ
    %PNBJO4QFDJpD
    -BOHVBHF%4-
    Λఏڙ͢ΔϑϨʔ
    ϜϫʔΫ

    View full-size slide

  24. ΍ͬͺΓʂ
    %4-ͳͷ͔ʂʂ

    View full-size slide

  25. ιʔεಡΜͰΈΑ͏
    w͖ͬͱEFTDSJCFؔ਺ͰϒϩοΫΛҾ
    ਺ʹͯ͠Δͱ͜Ζ͕͋Δ͸ͣ
    wEFTDSJCFͰͻͨ͢Β୳͢

    View full-size slide

  26. ιʔεಡΜͰΈΑ͏
    rspec-core/lib/spec/core/dsl.rb
    def describe(*args, &example_group_block)
    RSpec::Core::ExampleGroup.describe(*args,
    &example_group_block).register
    end

    View full-size slide

  27. ιʔεಡΜͰΈΑ͏
    rspec-core/lib/spec/core/dsl.rb
    def describe(*args, &example_group_block)
    RSpec::Core::ExampleGroup.describe(*args,
    &example_group_block).register
    end

    View full-size slide

  28. ιʔεಡΜͰΈΑ͏
    wEFTDSJCFؔ਺ݟ͚ͭͨ
    wҾ਺ͰϒϩοΫ౉ͯ͠Δ
    w͕͜͜34QFDͷग़ൃ఺
    w%4-͕֬ೝग़དྷͨ

    View full-size slide

  29. ෼͔͖ͬͯͨ
    describe Bowling, "#score" do
    it "returns 0 for all gutter game" do
    bowling = Bowling.new
    20.times { bowling.hit(0)}
    bowling.score.should eq(0)
    end
    end

    View full-size slide

  30. ෼͔͖ͬͯͨ
    describe Bowling, "#score" do
    it "returns 0 for all gutter game" do
    bowling = Bowling.new
    20.times { bowling.hit(0)}
    bowling.score.should eq(0)
    end
    end

    View full-size slide

  31. ෼͔͖ͬͯͨ
    describe Bowling, "#score" do
    it "returns 0 for all gutter game" do
    bowling = Bowling.new
    20.times { bowling.hit(0)}
    bowling.score.should eq(0)
    end
    end

    View full-size slide

  32. ෼͔͖ͬͯͨ
    wιʔεΛಡΉ͜ͱͰɺEFTDSJCF͕Կ
    ͯ͠Δ͔෼͔ͬͨ
    wJU΋Կͯ͠Δ͔෼͔ͬͨ

    View full-size slide

  33. ·ͱΊ
    w࠷ॳ͸34QFD࢖͚ͬͯͨͲɺશવͪΜ
    ΀Μ͔Μ΀Μͳঢ়ଶ
    w%4-Λ஌͔ͬͯΒɺ%4-ʹ͍ͭͯ΋ͬ
    ͱ஌Γͨ͘ͳͬͨ

    View full-size slide

  34. ·ͱΊ
    wͪΐ͏Ͳͦͷ࣌ɺݟͯͨ34QFD͕
    %4-ͩͱ͍͏͜ͱΛ஌Δ
    wͦΕ͔Β͸ɺ34QFDͷιʔεಡΜͩ
    Γɺ34QFDʹ͍ͭͯॻ͔Ε͍ͯΔهࣄ
    ΛಡΈ͋͞Δ
    w͖͔͚ͬ͸LBOB[BXBSCͩͬͨ

    View full-size slide

  35. ࣍΁
    wࠓ೔Λ͖͔͚ͬʹ࣍΁
    w%4-
    w34QFD΋ͬͱਂ͘
    w3VCZPO3BJMT
    w#%% 5%%
    wωλ͸ͨ͘͞Μ͋Δ

    View full-size slide

  36. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide