Your SlideShare is downloading. ×
Let's begin Behavior Driven Development using RSpec
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Let's begin Behavior Driven Development using RSpec

1,968
views

Published on

Introducing BDD and RSpec.

Introducing BDD and RSpec.


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

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2011.05.21http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 2. 2011 5 22
  • 3. mrkn Ruby Rubyhttp://www.flickr.com/photos/koichiroo/5244581973/2011 5 22
  • 4. 20112010 5 3 22 1
  • 5. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 6. 2011.05.21http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 7. 2011 5 22
  • 8. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 9. BDD Behavior Driven Development2011 5 22
  • 10. TDD Test Driven Development2011 5 22
  • 11. TDD Test Driven Development2011 5 22
  • 12. TDD BDD2011 5 22
  • 13. 2011 5 22
  • 14. 2011 5 22
  • 15. 2011 5 22
  • 16. 2011 5 22
  • 17. test-unit2011 5 22
  • 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. RSpec2011 5 22
  • 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. 2011 5 22
  • 22. 2011 5 22
  • 23. 2011 5 22
  • 24. TDD2011 5 22
  • 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. !"#$%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. !"#$%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. !"#$%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. !"#$%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. http://blogs.itmedia.co.jp/hiranabe/2005/08/sd4__c05e.html2011 5 22
  • 31. http://blogs.itmedia.co.jp/hiranabe/2005/10/tdd__bdd__731d.html2011 5 22
  • 32. 2011 5 22
  • 33. 2011 5 22
  • 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. 2011 5 22
  • 36. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 37. 2011 5 22
  • 38. 2011 5 22
  • 39. 2011 5 22
  • 40. 2011 5 22
  • 41. http://gihyo.jp/dev/serial/01/ruby/00392011 5 22
  • 42. http://www.nicovideo.jp/watch/sm129758492011 5 22
  • 43. 2011 5 22
  • 44. 2011 5 22
  • 45. gem install rspec2011 5 22
  • 46. rspec rspec-core rspec-expectations rspec-mocks2011 5 22
  • 47. 2011 5 22
  • 48. gem install rspec2011 5 22
  • 49. http://www.flickr.com/photos/bruce_mcadam/3214482163/2011 5 22
  • 50. 2011 5 22
  • 51. 2011 5 22
  • 52. 2011 5 22
  • 53. 2011 5 22
  • 54. require ‘spec/test/unit’2011 5 22
  • 55. ‘spec/test/unit’2011 5 22
  • 56. http://www.slideshare.net/t_wada/sapporo-rubykaigi01-twada-lt-presentation2011 5 22
  • 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. 2011 5 22
  • 59. 2011 5 22
  • 60. 2011 5 22
  • 61. 2011 5 22
  • 62. Photo by rla579: http://flickr.com/photos/rla579/2482286520/2011 5 22
  • 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. 2011 5 22
  • 65. 2011 5 22
  • 66. 2011 5 22
  • 67. FizzBuzzCounter2011 5 22
  • 68. 2011 5 22
  • 69. # FizzBuzzCounter.new.each do |i| p i end #=> 1 # 2 # “Fizz” # 4 # “Buzz”2011 5 22
  • 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. # Enumerable fbc = FizzBuzzCounter.new p fbc.take(3) #=> [1, 2, “Fizz”] p fbc.take(3) #=> [4, “Buzz”, “Fizz”]2011 5 22
  • 72. 2011 5 22
  • 73. spec/ spec_helper.rb require ‘spec_helper’2011 5 22
  • 74. Live Coding2011 5 22
  • 75. RSpec Best Practicehttp://jp.rubyist.net/magazine/?0032-TranslationArticle2011 5 22
  • 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. 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. Observer Pattern2011 5 22
  • 79. observers 1 * subject + change()2011 5 22
  • 80. 2011 5 22
  • 81. 2011 5 22
  • 82. 2011 5 22
  • 83. 2011 5 22
  • 84. Test Double2011 5 22
  • 85. describe ConcreteObservable do describe ‘#change’ do it ‘calls its notify()’ do subject.should_receive(:notify) subject.change end end end2011 5 22
  • 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. http://ironruby.codeplex.com/2011 5 22