Let's begin Behavior Driven Development using RSpec

2,193
-1

Published on

Introducing BDD and RSpec.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,193
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
33
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Let's begin Behavior Driven Development using RSpec

  1. 1. 2011.05.21http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  2. 2. 2011 5 22
  3. 3. mrkn Ruby Rubyhttp://www.flickr.com/photos/koichiroo/5244581973/2011 5 22
  4. 4. 20112010 5 3 22 1
  5. 5. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  6. 6. 2011.05.21http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  7. 7. 2011 5 22
  8. 8. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  9. 9. BDD Behavior Driven Development2011 5 22
  10. 10. TDD Test Driven Development2011 5 22
  11. 11. TDD Test Driven Development2011 5 22
  12. 12. TDD BDD2011 5 22
  13. 13. 2011 5 22
  14. 14. 2011 5 22
  15. 15. 2011 5 22
  16. 16. 2011 5 22
  17. 17. test-unit2011 5 22
  18. 18. module System class AgeCalculatorTest < Test::Unit::TestCase include RR::Adapters::TestUnit def setup @calc = AgeCalculator.with_birthday(1981, 7, 20) end def test_age_on assert_equal(29, @calc.age_on(2011, 7, 19)) assert_equal(30, @calc.age_on(2011, 7, 20)) end def test_age_today d, m, y = [*Time.now][3..5] stub(@calc).age_on @calc.age_on_today assert_received(@calc) {|c| c.age_on(y, m, d) } end end end2011 5 22
  19. 19. RSpec2011 5 22
  20. 20. module System describe AgeCalculator do context ‘with birthday 1981-07-20’ do subject { AgeCalculator.with_birthday(1981, 7, 20) } describe ‘#age_on’ do context ‘with 2011-07-19’ do specify ‘the age is 29’ do subject.age_on(2011, 7, 19).should be == 29 end end context ‘with 2011-07-20’ do specify ‘the age is 30’ do subject.age_on(2011, 7, 20).should be == 30 end end end describe ‘#age_on_today’ do it ‘calls age_on with year, month, and day on today’ do d, m, y = [*Time.now][3..5] subject.should_receive(:age_on).with(y, m, d) subject.age_on_today end end end end end2011 5 22
  21. 21. 2011 5 22
  22. 22. 2011 5 22
  23. 23. 2011 5 22
  24. 24. TDD2011 5 22
  25. 25. !Test"#$% &()$* t-wada http://d.hatena.ne.jp/t-wada/ 2005+7,23- @J2EE./012103http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf2011 5 22
  26. 26. !"#$%1 ! TDD&()*+,&-. ! "Test"/01213.45%&6784 " 9:;<=>?@A " 2B%"Test"CDE&-.FGHIJKLF " MNO5PQCRS ! ()TUVWXOYZ[4 " 9:#/ ]^#/ >?@A_`http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf2011 5 22
  27. 27. !"#$%1 ! TDD&()*+,&-. ! "Test"/01213.45%&6784 " 9:;<=>?@A " 2B%"Test"CDE&-.FGHIJKLF " MNO5PQCRS ! ()TUVWXOYZ[4 " 9:#/ ]^#/ >?@A_`http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf2011 5 22
  28. 28. !"#$%2 ! TDD%"Test"&(())%*+%,% " -./0(12%345 ! TDD%67&89:;<=/>?@ABCD :;EFG>/HIJKLhttp://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf2011 5 22
  29. 29. !"#$%2 ! TDD%"Test"&(())%*+%,% " -./0(12%345 ! TDD%67&89:;<=/>?@ABCD :;EFG>/HIJKLhttp://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf2011 5 22
  30. 30. http://blogs.itmedia.co.jp/hiranabe/2005/08/sd4__c05e.html2011 5 22
  31. 31. http://blogs.itmedia.co.jp/hiranabe/2005/10/tdd__bdd__731d.html2011 5 22
  32. 32. 2011 5 22
  33. 33. 2011 5 22
  34. 34. module System describe AgeCalculator do context ‘with birthday 1981-07-20’ do subject { AgeCalculator.with_birthday(1981, 7, 20) } describe ‘#age_on’ do context ‘with 2011-07-19’ do specify ‘the age is 29’ do subject.age_on(2011, 7, 19).should be == 29 end end context ‘with 2011-07-20’ do specify ‘the age is 30’ do subject.age_on(2011, 7, 20).should be == 30 end end end describe ‘#age_on_today’ do it ‘calls age_on with year, month, and day on today’ do d, m, y = [*Time.now][3..5] subject.should_receive(:age_on).with(y, m, d) subject.age_on_today end end end end end2011 5 22
  35. 35. 2011 5 22
  36. 36. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  37. 37. 2011 5 22
  38. 38. 2011 5 22
  39. 39. 2011 5 22
  40. 40. 2011 5 22
  41. 41. http://gihyo.jp/dev/serial/01/ruby/00392011 5 22
  42. 42. http://www.nicovideo.jp/watch/sm129758492011 5 22
  43. 43. 2011 5 22
  44. 44. 2011 5 22
  45. 45. gem install rspec2011 5 22
  46. 46. rspec rspec-core rspec-expectations rspec-mocks2011 5 22
  47. 47. 2011 5 22
  48. 48. gem install rspec2011 5 22
  49. 49. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  50. 50. 2011 5 22
  51. 51. 2011 5 22
  52. 52. 2011 5 22
  53. 53. 2011 5 22
  54. 54. require ‘spec/test/unit’2011 5 22
  55. 55. ‘spec/test/unit’2011 5 22
  56. 56. http://www.slideshare.net/t_wada/sapporo-rubykaigi01-twada-lt-presentation2011 5 22
  57. 57. (a.k.a id:t-wada) Oct, 26, 2008 @SapporoRubyKaigi 01http://www.slideshare.net/t_wada/sapporo-rubykaigi01-twada-lt-presentation2011 5 22
  58. 58. 2011 5 22
  59. 59. 2011 5 22
  60. 60. 2011 5 22
  61. 61. 2011 5 22
  62. 62. Photo by rla579: http://flickr.com/photos/rla579/2482286520/2011 5 22
  63. 63. Working Effectively with Legacy tDiary Code using Cucumber and RSpec KAKUTANI Shintaro; Eiwa System Management,Inc.; Nihon Ruby-no-kaihttp://kakutani.com/articles/working_effectively_with_legacy_tdiary_code_using_cucumber_and_rspec.pdf2011 5 22
  64. 64. 2011 5 22
  65. 65. 2011 5 22
  66. 66. 2011 5 22
  67. 67. FizzBuzzCounter2011 5 22
  68. 68. 2011 5 22
  69. 69. # FizzBuzzCounter.new.each do |i| p i end #=> 1 # 2 # “Fizz” # 4 # “Buzz”2011 5 22
  70. 70. # fbc = FizzBuzzCounter.new p fbc.next #=> 1 p fbc.next #=> 2 p fbc.next #=> “Fizz” fbc.each {|i| break if i > 14 } p fbc.next #=> “FizzBuzz”2011 5 22
  71. 71. # Enumerable fbc = FizzBuzzCounter.new p fbc.take(3) #=> [1, 2, “Fizz”] p fbc.take(3) #=> [4, “Buzz”, “Fizz”]2011 5 22
  72. 72. 2011 5 22
  73. 73. spec/ spec_helper.rb require ‘spec_helper’2011 5 22
  74. 74. Live Coding2011 5 22
  75. 75. RSpec Best Practicehttp://jp.rubyist.net/magazine/?0032-TranslationArticle2011 5 22
  76. 76. describe FizzBuzzCounter do describe ‘.filter’ do context ‘with 1’ do it ‘returns 1’ do FizzBuzzCounter. filter(1).should be == 1 end end end end2011 5 22
  77. 77. describe FizzBuzzCounter do describe ‘.filter’ do context ‘with 1’ do it ‘returns 1’ do FizzBuzzCounter. filter(1).should be == 1 end end end end2011 5 22
  78. 78. Observer Pattern2011 5 22
  79. 79. observers 1 * subject + change()2011 5 22
  80. 80. 2011 5 22
  81. 81. 2011 5 22
  82. 82. 2011 5 22
  83. 83. 2011 5 22
  84. 84. Test Double2011 5 22
  85. 85. describe ConcreteObservable do describe ‘#change’ do it ‘calls its notify()’ do subject.should_receive(:notify) subject.change end end end2011 5 22
  86. 86. describe ConcreteObservable do describe ‘#change’ do subject { ConcreteObservable.new } it “calls observers’ update()” do observer = double(‘an observer’) observer.should_receive(:update) subject.change end end end2011 5 22
  87. 87. http://ironruby.codeplex.com/2011 5 22
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×