際際滷

際際滷Share a Scribd company logo
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://?ickr.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

Let's begin Behavior Driven Development using RSpec