SlideShare a Scribd company logo
1 of 87
Download to read offline
2011.05.21
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
2011   5   22
mrkn



           Ruby
           Ruby



http://www.flickr.com/photos/koichiroo/5244581973/
2011   5   22
2011
2010   5
       3   22
           1
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
2011.05.21
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
2011   5   22
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
BDD
                Behavior Driven Development




2011   5   22
TDD
                Test Driven Development




2011   5   22
TDD
                Test Driven Development




2011   5   22
TDD   BDD


2011   5   22
2011   5   22
2011   5   22
2011   5   22
2011   5   22
test-unit

2011   5   22
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
  end




2011   5   22
RSpec

2011   5   22
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
  end




2011   5   22
2011   5   22
2011   5   22
2011   5   22
TDD




2011   5   22
!Test"#$%
                     &'()$*
                                                   t-wada
                                       http://d.hatena.ne.jp/t-wada/
                                              2005+7,23-
                                         @J2EE./012103




http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf
2011   5   22
!"#$%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.pdf
2011   5   22
!"#$%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.pdf
2011   5   22
!"#$%2
                    !   TDD%"Test"&'(())%*+%,%
                        "   -./0'(12%345
                    !   TDD%67&89:;<=/>?@ABCD
                        :;EFG>/HIJKL




http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf
2011   5   22
!"#$%2
                    !   TDD%"Test"&'(())%*+%,%
                        "   -./0'(12%345
                    !   TDD%67&89:;<=/>?@ABCD
                        :;EFG>/HIJKL




http://www.ne.jp/asahi/t/wada/articles/Test_in_TDD.pdf
2011   5   22
http://blogs.itmedia.co.jp/hiranabe/2005/08/sd4__c05e.html
2011   5   22
http://blogs.itmedia.co.jp/hiranabe/2005/10/tdd__bdd__731d.html
2011   5   22
2011   5   22
2011   5   22
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
  end




2011   5   22
2011   5   22
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
2011   5   22
2011   5   22
2011   5   22
2011   5   22
http://gihyo.jp/dev/serial/01/ruby/0039
2011   5   22
http://www.nicovideo.jp/watch/sm12975849
2011   5   22
2011   5   22
2011   5   22
gem install rspec



2011   5   22
rspec
                     rspec-core
                rspec-expectations
                    rspec-mocks

2011   5   22
2011   5   22
gem install rspec




2011   5   22
http://www.flickr.com/photos/bruce_mcadam/3214482163/
2011   5   22
2011   5   22
2011   5   22
2011   5   22
2011   5   22
require ‘spec/test/unit’




2011   5   22
‘spec/test/unit’




2011   5   22
http://www.slideshare.net/t_wada/sapporo-rubykaigi01-twada-lt-presentation
2011   5   22
(a.k.a id:t-wada)
                                 Oct, 26, 2008 @SapporoRubyKaigi 01




http://www.slideshare.net/t_wada/sapporo-rubykaigi01-twada-lt-presentation
2011   5   22
2011   5   22
2011   5   22
2011   5   22
2011   5   22
Photo by rla579: http://flickr.com/photos/rla579/2482286520/
2011   5   22
Working Effectively with Legacy tDiary Code
                using Cucumber and RSpec


                KAKUTANI Shintaro; Eiwa System Management,Inc.; Nihon Ruby-no-kai




http://kakutani.com/articles/working_effectively_with_legacy_tdiary_code_using_cucumber_and_rspec.pdf
2011   5   22
2011   5   22
2011   5   22
2011   5   22
FizzBuzzCounter


2011   5   22
2011   5   22
#
  FizzBuzzCounter.new.each do |i|
    p i
  end
  #=> 1
  #   2
  #   “Fizz”
  #   4
  #   “Buzz”


2011   5   22
#
  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
# Enumerable
  fbc = FizzBuzzCounter.new
  p fbc.take(3) #=> [1, 2, “Fizz”]
  p fbc.take(3) #=> [4, “Buzz”, “Fizz”]




2011   5   22
2011   5   22
spec/
                spec_helper.rb
                  require ‘spec_helper’


2011   5   22
Live Coding

2011   5   22
RSpec Best Practice
http://jp.rubyist.net/magazine/?0032-TranslationArticle
2011   5   22
describe FizzBuzzCounter do
    describe ‘.filter’ do
      context ‘with 1’ do
        it ‘returns 1’ do
          FizzBuzzCounter.
            filter(1).should be == 1
        end
      end
    end
  end


2011   5   22
describe FizzBuzzCounter do
    describe ‘.filter’ do
      context ‘with 1’ do
        it ‘returns 1’ do
          FizzBuzzCounter.
            filter(1).should be == 1
        end
      end
    end
  end


2011   5   22
Observer Pattern


2011   5   22
observers
                                       1           *




                subject

                          + change()




2011   5   22
2011   5   22
2011   5   22
2011   5   22
2011   5   22
Test Double


2011   5   22
describe ConcreteObservable do
    describe ‘#change’ do
      it ‘calls its notify()’ do
        subject.should_receive(:notify)
        subject.change
      end
    end
  end




2011   5   22
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
  end



2011   5   22
http://ironruby.codeplex.com/
2011   5   22

More Related Content

Viewers also liked

Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点Kenta Murata
 
The world without float literal
The world without float literalThe world without float literal
The world without float literalKenta Murata
 
The world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbersThe world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbersKenta Murata
 
Ruby 拡張モジュール入門
Ruby 拡張モジュール入門Ruby 拡張モジュール入門
Ruby 拡張モジュール入門Kenta Murata
 
関数型プログラミングの世界
関数型プログラミングの世界関数型プログラミングの世界
関数型プログラミングの世界Kenta Murata
 
Introduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecIntroduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecKenta Murata
 

Viewers also liked (7)

Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点Ruby 1.9.3 の新機能と変更点
Ruby 1.9.3 の新機能と変更点
 
The world without float literal
The world without float literalThe world without float literal
The world without float literal
 
The world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbersThe world without the literal notation for floating-point numbers
The world without the literal notation for floating-point numbers
 
Ruby 拡張モジュール入門
Ruby 拡張モジュール入門Ruby 拡張モジュール入門
Ruby 拡張モジュール入門
 
関数型プログラミングの世界
関数型プログラミングの世界関数型プログラミングの世界
関数型プログラミングの世界
 
Introduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpecIntroduction to ATDD with Cucumber and RSpec
Introduction to ATDD with Cucumber and RSpec
 
Float is Legacy
Float is LegacyFloat is Legacy
Float is Legacy
 

Similar to Let's begin Behavior Driven Development using RSpec

Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Hirofumi Iwasaki
 
Taking Your Content Mobile
Taking Your Content MobileTaking Your Content Mobile
Taking Your Content MobileJeremy Johnson
 
Steering Iterative and Incremental Delivery with Jeff Patton
Steering Iterative and Incremental Delivery with Jeff PattonSteering Iterative and Incremental Delivery with Jeff Patton
Steering Iterative and Incremental Delivery with Jeff PattonUIEpreviews
 
Refactor to Reactive With Spring 5 and Project Reactor
Refactor to Reactive With Spring 5 and Project ReactorRefactor to Reactive With Spring 5 and Project Reactor
Refactor to Reactive With Spring 5 and Project ReactorEatDog
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSMartin Hochel
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSPat Cito
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022Johnny Sung
 
Meck at erlang factory, london 2011
Meck at erlang factory, london 2011Meck at erlang factory, london 2011
Meck at erlang factory, london 2011Adam Lindberg
 
TDDBCの前にTDDについて知っておいてもらいたい3つのこと
TDDBCの前にTDDについて知っておいてもらいたい3つのことTDDBCの前にTDDについて知っておいてもらいたい3つのこと
TDDBCの前にTDDについて知っておいてもらいたい3つのことTakeshi Kakeda
 
Mutation Testing DevoxxUK 2021
Mutation Testing DevoxxUK 2021Mutation Testing DevoxxUK 2021
Mutation Testing DevoxxUK 2021Paco van Beckhoven
 
Location and Language in Social Media (Stanford Mobi Social Invited Talk)
Location and Language in Social Media (Stanford Mobi Social Invited Talk)Location and Language in Social Media (Stanford Mobi Social Invited Talk)
Location and Language in Social Media (Stanford Mobi Social Invited Talk)Ed Chi
 
110304 smart grid cleantech innovation
110304 smart grid cleantech innovation110304 smart grid cleantech innovation
110304 smart grid cleantech innovationHiroshi Yagi
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...Sencha
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
Tdd & clean code
Tdd & clean codeTdd & clean code
Tdd & clean codeEyal Vardi
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway ichikaway
 
CFP: Optimiation on Complex Systems
CFP: Optimiation on Complex SystemsCFP: Optimiation on Complex Systems
CFP: Optimiation on Complex SystemsMario Pavone
 
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.UA Mobile
 

Similar to Let's begin Behavior Driven Development using RSpec (20)

Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)
 
Taking Your Content Mobile
Taking Your Content MobileTaking Your Content Mobile
Taking Your Content Mobile
 
Steering Iterative and Incremental Delivery with Jeff Patton
Steering Iterative and Incremental Delivery with Jeff PattonSteering Iterative and Incremental Delivery with Jeff Patton
Steering Iterative and Incremental Delivery with Jeff Patton
 
Refactor to Reactive With Spring 5 and Project Reactor
Refactor to Reactive With Spring 5 and Project ReactorRefactor to Reactive With Spring 5 and Project Reactor
Refactor to Reactive With Spring 5 and Project Reactor
 
RSpec
RSpecRSpec
RSpec
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJS
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
 
Vhdl ppt
Vhdl pptVhdl ppt
Vhdl ppt
 
Meck at erlang factory, london 2011
Meck at erlang factory, london 2011Meck at erlang factory, london 2011
Meck at erlang factory, london 2011
 
TDDBCの前にTDDについて知っておいてもらいたい3つのこと
TDDBCの前にTDDについて知っておいてもらいたい3つのことTDDBCの前にTDDについて知っておいてもらいたい3つのこと
TDDBCの前にTDDについて知っておいてもらいたい3つのこと
 
Mutation Testing DevoxxUK 2021
Mutation Testing DevoxxUK 2021Mutation Testing DevoxxUK 2021
Mutation Testing DevoxxUK 2021
 
Location and Language in Social Media (Stanford Mobi Social Invited Talk)
Location and Language in Social Media (Stanford Mobi Social Invited Talk)Location and Language in Social Media (Stanford Mobi Social Invited Talk)
Location and Language in Social Media (Stanford Mobi Social Invited Talk)
 
110304 smart grid cleantech innovation
110304 smart grid cleantech innovation110304 smart grid cleantech innovation
110304 smart grid cleantech innovation
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Tdd & clean code
Tdd & clean codeTdd & clean code
Tdd & clean code
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
CFP: Optimiation on Complex Systems
CFP: Optimiation on Complex SystemsCFP: Optimiation on Complex Systems
CFP: Optimiation on Complex Systems
 
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.
The Flexible Layout Kit (how we got rid of web views). UA Mobile 2016.
 

More from Kenta Murata

Rubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていることRubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていることKenta Murata
 
Ruby の懸案事項
Ruby の懸案事項Ruby の懸案事項
Ruby の懸案事項Kenta Murata
 
5分弱で分かる量子ビット
5分弱で分かる量子ビット5分弱で分かる量子ビット
5分弱で分かる量子ビットKenta Murata
 
Rubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimalRubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimalKenta Murata
 
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)Kenta Murata
 
校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your schoolKenta Murata
 
Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Kenta Murata
 
5分で分かる Measure
5分で分かる Measure5分で分かる Measure
5分で分かる MeasureKenta Murata
 
Measure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリMeasure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリKenta Murata
 
情報学特論#02
情報学特論#02情報学特論#02
情報学特論#02Kenta Murata
 
情報学特論#01
情報学特論#01情報学特論#01
情報学特論#01Kenta Murata
 
北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせKenta Murata
 

More from Kenta Murata (12)

Rubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていることRubyをたのしくするために私が考えていること
Rubyをたのしくするために私が考えていること
 
Ruby の懸案事項
Ruby の懸案事項Ruby の懸案事項
Ruby の懸案事項
 
5分弱で分かる量子ビット
5分弱で分かる量子ビット5分弱で分かる量子ビット
5分弱で分かる量子ビット
 
Rubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimalRubykaigi2010mrkn bigdecimal
Rubykaigi2010mrkn bigdecimal
 
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
Ruby における絵文字エンコーディング間の相互変換ダイアグラム (案)
 
校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school校内勉強会のススメ An encouragement to hold workshops In your school
校内勉強会のススメ An encouragement to hold workshops In your school
 
Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案Ruby の標準乱数生成器とその改善案
Ruby の標準乱数生成器とその改善案
 
5分で分かる Measure
5分で分かる Measure5分で分かる Measure
5分で分かる Measure
 
Measure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリMeasure 単位付き数値ライブラリ
Measure 単位付き数値ライブラリ
 
情報学特論#02
情報学特論#02情報学特論#02
情報学特論#02
 
情報学特論#01
情報学特論#01情報学特論#01
情報学特論#01
 
北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ北海道関数型言語勉強会@札幌#2のお知らせ
北海道関数型言語勉強会@札幌#2のお知らせ
 

Let's begin Behavior Driven Development using RSpec