第3回BDD勉強会
フィードバックと改善
フィードバックを得る
•   重複する数字を扱う方法に問題あり


    •   暗号が1234の時に推測を1155とすると
        採点が+ーとなってしまう
要件を決定
•   推測したそれぞれの数値は一度きりの一致のみ有効


•   例)暗号が1234で推測が1134の場合
      結果は+++になる


    •   2番目の1は無視される
修正の手順


• Featureの修正
• RSpecにサンプルを追加
• プログラムコードの修正
Feature修正
Scenarios: matches with duplicates
 | code | guess | mark |
 | 1234 | 1155 | +     |
 | 1234 | 5115 | -     |
 | 1134 | 1155 | ++ |
 | 1134 | 5115 | +- |
 | 1134 | 5511 | --    |
 | 1134 | 1115 | ++ |
 | 1134 | 5111 | +- |
RSpecサンプル修正
context "with 1 exact match duplicated in guess" do
 it "returns 0" do
   pending("refactor number_match_count")
   marker = Marker.new('1234','1155')
   marker.number_match_count.should == 0
 end
end

           最初はpendingにしておくことで
       新しい失敗が発生しても混同しなくなる
RSpec
•   サブジェクトコード
     RSpecを使って振る舞いを指定するコード

•   エクスペクテーション
     →アサーション

•   サンプルコード
     →テスト

•   サンプルグループ
     →テストケース

•   スペック
     →1つ以上のサンプルを含んでいるファイル
サンプルグループ


  サンプルコード
              describe "A new Account" do
     サブジェクト    it "should have a balance of 0" do
                 account = Account.new
     コード




                 account.balance.should == Money.new(0, :USD)
               end
              end
サンプルグループ

• describeメソッド
• contextメソッド
• 対象を説明する場合はdescribe
 状態を説明する場合はcontext
 が一般的?
describe User, "with no roles assigned" do
 ...
end
=> User with no roles assigned

describe User, "(ロール未割り当て)" do
 ...
end
=> User (ロール未割り当て)
module Authentication
 describe User, "with no roles assigned" do
  ...
 end
end
=> Authentication::User with no roles assigned
describe User do
 describe "with no roles assigned" do
  it "is not allowed to view protected content"
    ...
  end
 end
end
=>User
    with no roles assigned
     is not allowed to view protected content
サンプルコード
describe Stack do
 before(:each) do
  @stack = Stack.new
  @stack.push :item
 end

 describe "#peek" do
  it "should return the top element" do
    @stack.peek.should == :item
  end
 end
end
Stack
    #peek
      should return the top element

shouldを消すとさらにドキュメントぽくなる

       Stack
        #peek
          return the top element

         Stack
          #peek
            先頭の要素を返す
サンプルを保留扱いにする
it "should be read all over"
it "should not be mixed with french fries" do
  pending "cleaning out the fryer"
  ...
end
it "should be empty" do
  pending ("bug report 18976") do
    [].should be_empty
  end
end
フック


• before(:each)、before(:all)
• after(:each)、after(:all)
• around(:each)
ヘルパーメソッド
 describe Thing do
  def create_thing(options) do
    thing = Thing.new
    thing.set_status(options[:status])
    thing
  end
  it "should do something when ok" do
    thing = create_thing(:status => "ok")
    ...
  end
 end
複数のサンプルグループで共有したい場合はmoduleでくくる
サンプルの共有
shared_examples_for "any pizza" do
 it "tastes really good" do
   @pizza.should taste_really_good
 end

 it "is available by the slice" do
    @pizza.should be available_by_the_slice
  end
end
describe "New York style thin crust pizza" do
 before :each do
   @pizza = Pizza.new(:region => "New York",
                          :style => "thin crust")
 end
 it behaves_like "any pizza"
 it "has a really great sauce" do
   @pizza.should have_a_really_great_sauce
 end
end

More Related Content

KEY
BDD勉強会 第6回
PPTX
JavaScriptクイックスタート
PDF
Weeklycms20120218
PDF
ノンプログラマーでも明日から使えるJavaScript簡単プログラム 先生:柳井 政和
PDF
C++コミュニティーの中心でC++をDISる
KEY
How wonderful to be (statically) typed 〜型が付くってスバラシイ〜
PPTX
知ってるようで意外と知らないPHPの便利関数
PDF
Functional JavaScript with Lo-Dash.js
BDD勉強会 第6回
JavaScriptクイックスタート
Weeklycms20120218
ノンプログラマーでも明日から使えるJavaScript簡単プログラム 先生:柳井 政和
C++コミュニティーの中心でC++をDISる
How wonderful to be (statically) typed 〜型が付くってスバラシイ〜
知ってるようで意外と知らないPHPの便利関数
Functional JavaScript with Lo-Dash.js

What's hot (20)

PDF
JavaScript入門
PPTX
PHP基本的関数QUIZ
PDF
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
KEY
Perlで伝統芸能
PPTX
BoostAsioで可読性を求めるのは間違っているだろうか
PDF
PHP5.5新機能「ジェネレータ」初心者入門
PDF
Enumはデキる子 ~ case .Success(let value): ~
PDF
15分でざっくり分かるScala入門
PDF
Prophecyを使ったユニットテスト
PDF
超絶技巧プログラミングの世界(FTD2015)
PDF
PDF
F#+Erlangで簡単なシューティングゲームを作ってみている
PDF
仕事の手離れを良くする手段としての、静的検査のあるテンプレートエンジン (YATT::Lite talk at 2014 テンプレートエンジンNight)
PDF
traitを使って楽したい話
PDF
よいことも悪いこともぜんぶPHPが教えてくれた
PDF
メタメタプログラミングRuby
KEY
あらためてPHP5.3
PDF
Phantom Type in Scala
PDF
phpspecで学ぶLondon School TDD
PDF
新しくプログラミング言語・・・Rubyでやってみた
JavaScript入門
PHP基本的関数QUIZ
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
Perlで伝統芸能
BoostAsioで可読性を求めるのは間違っているだろうか
PHP5.5新機能「ジェネレータ」初心者入門
Enumはデキる子 ~ case .Success(let value): ~
15分でざっくり分かるScala入門
Prophecyを使ったユニットテスト
超絶技巧プログラミングの世界(FTD2015)
F#+Erlangで簡単なシューティングゲームを作ってみている
仕事の手離れを良くする手段としての、静的検査のあるテンプレートエンジン (YATT::Lite talk at 2014 テンプレートエンジンNight)
traitを使って楽したい話
よいことも悪いこともぜんぶPHPが教えてくれた
メタメタプログラミングRuby
あらためてPHP5.3
Phantom Type in Scala
phpspecで学ぶLondon School TDD
新しくプログラミング言語・・・Rubyでやってみた
Ad

Similar to 第3回BDD勉強会 (20)

ODP
RSpecのここがすごい!
PDF
Ruby 3の型推論やってます
PDF
Introduction to Spock
PDF
Meta programing ruby monday
PDF
現実世界のJRuby(ショートバージョン)
PDF
魂のコーディング
PDF
RubyとActive Support for expert 2
KEY
実録!Railsのはまりポイント10選
PPT
Start!! Ruby
PDF
名古屋Ruby会議02 LT:Ruby中級への道
PDF
現実世界のJRuby
PPTX
第3回輪講
KEY
Clojure programming-chapter-2
PDF
最近の単体テスト
PDF
20110820 metaprogramming
PDF
設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】
PDF
型プロファイラ:抽象解釈に基づくRuby 3の静的解析
PDF
Clojure
PDF
Ruby 初級者向けレッスン 49回───クラス
RSpecのここがすごい!
Ruby 3の型推論やってます
Introduction to Spock
Meta programing ruby monday
現実世界のJRuby(ショートバージョン)
魂のコーディング
RubyとActive Support for expert 2
実録!Railsのはまりポイント10選
Start!! Ruby
名古屋Ruby会議02 LT:Ruby中級への道
現実世界のJRuby
第3回輪講
Clojure programming-chapter-2
最近の単体テスト
20110820 metaprogramming
設計/原理 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第28回】
型プロファイラ:抽象解釈に基づくRuby 3の静的解析
Clojure
Ruby 初級者向けレッスン 49回───クラス
Ad

Recently uploaded (12)

PDF
【VISIONARY JAPAN】エンジニアチーム 採用ピッチ資料(ver2.1)
PDF
RailsエンジニアのためのActive Recordの基礎から学ぶ実践的DB連携
PDF
[スクフェス大阪2024]組織は人でできている~組織をマルチレイヤーアジャイルでコネクトしよう~
PPTX
だれでもサクッと使える!採用ピッチ資料テンプレート(解説付き)_20230529_ver1.pptx
PDF
神奈川県の伊勢原市商工会で中小企業講演「人手不足を解消するためのAI活用セミナー」
PDF
東京商工会議所荒川支部で中小企業講演「今日から使える!省力化・効率化に向けた生成AI活用入門」
PDF
GN Business Consulting会社概要 (FREE CASH MAKER)_saleshub.pdf
PDF
AIゲートウェイ、グローバルトップ12企業のランキングと市場シェア2025.pdf
PPTX
Setting KPI of Estimation Department Division
PDF
202508株式会社なぞるマーケティング組織開発・学習支援サービス_概要資料
PDF
2508slide_townobuse_nagano_chohoobuse.pdf
PDF
[アジャイルジャパン2024]組織をアジャイルにしていくのに プロジェクトファシリテーションが必要ないわけがない
【VISIONARY JAPAN】エンジニアチーム 採用ピッチ資料(ver2.1)
RailsエンジニアのためのActive Recordの基礎から学ぶ実践的DB連携
[スクフェス大阪2024]組織は人でできている~組織をマルチレイヤーアジャイルでコネクトしよう~
だれでもサクッと使える!採用ピッチ資料テンプレート(解説付き)_20230529_ver1.pptx
神奈川県の伊勢原市商工会で中小企業講演「人手不足を解消するためのAI活用セミナー」
東京商工会議所荒川支部で中小企業講演「今日から使える!省力化・効率化に向けた生成AI活用入門」
GN Business Consulting会社概要 (FREE CASH MAKER)_saleshub.pdf
AIゲートウェイ、グローバルトップ12企業のランキングと市場シェア2025.pdf
Setting KPI of Estimation Department Division
202508株式会社なぞるマーケティング組織開発・学習支援サービス_概要資料
2508slide_townobuse_nagano_chohoobuse.pdf
[アジャイルジャパン2024]組織をアジャイルにしていくのに プロジェクトファシリテーションが必要ないわけがない

第3回BDD勉強会

  • 3. フィードバックを得る • 重複する数字を扱う方法に問題あり • 暗号が1234の時に推測を1155とすると 採点が+ーとなってしまう
  • 4. 要件を決定 • 推測したそれぞれの数値は一度きりの一致のみ有効 • 例)暗号が1234で推測が1134の場合   結果は+++になる • 2番目の1は無視される
  • 6. Feature修正 Scenarios: matches with duplicates | code | guess | mark | | 1234 | 1155 | + | | 1234 | 5115 | - | | 1134 | 1155 | ++ | | 1134 | 5115 | +- | | 1134 | 5511 | -- | | 1134 | 1115 | ++ | | 1134 | 5111 | +- |
  • 7. RSpecサンプル修正 context "with 1 exact match duplicated in guess" do it "returns 0" do pending("refactor number_match_count") marker = Marker.new('1234','1155') marker.number_match_count.should == 0 end end 最初はpendingにしておくことで 新しい失敗が発生しても混同しなくなる
  • 9. サブジェクトコード  RSpecを使って振る舞いを指定するコード • エクスペクテーション  →アサーション • サンプルコード  →テスト • サンプルグループ  →テストケース • スペック  →1つ以上のサンプルを含んでいるファイル
  • 10. サンプルグループ サンプルコード describe "A new Account" do サブジェクト it "should have a balance of 0" do account = Account.new コード account.balance.should == Money.new(0, :USD) end end
  • 11. サンプルグループ • describeメソッド • contextメソッド • 対象を説明する場合はdescribe 状態を説明する場合はcontext が一般的?
  • 12. describe User, "with no roles assigned" do ... end => User with no roles assigned describe User, "(ロール未割り当て)" do ... end => User (ロール未割り当て)
  • 13. module Authentication describe User, "with no roles assigned" do ... end end => Authentication::User with no roles assigned
  • 14. describe User do describe "with no roles assigned" do it "is not allowed to view protected content" ... end end end =>User with no roles assigned is not allowed to view protected content
  • 15. サンプルコード describe Stack do before(:each) do @stack = Stack.new @stack.push :item end describe "#peek" do it "should return the top element" do @stack.peek.should == :item end end end
  • 16. Stack #peek should return the top element shouldを消すとさらにドキュメントぽくなる Stack #peek return the top element Stack #peek 先頭の要素を返す
  • 17. サンプルを保留扱いにする it "should be read all over" it "should not be mixed with french fries" do pending "cleaning out the fryer" ... end it "should be empty" do pending ("bug report 18976") do [].should be_empty end end
  • 19. ヘルパーメソッド describe Thing do def create_thing(options) do thing = Thing.new thing.set_status(options[:status]) thing end it "should do something when ok" do thing = create_thing(:status => "ok") ... end end 複数のサンプルグループで共有したい場合はmoduleでくくる
  • 20. サンプルの共有 shared_examples_for "any pizza" do it "tastes really good" do @pizza.should taste_really_good end it "is available by the slice" do @pizza.should be available_by_the_slice end end
  • 21. describe "New York style thin crust pizza" do before :each do @pizza = Pizza.new(:region => "New York", :style => "thin crust") end it behaves_like "any pizza" it "has a really great sauce" do @pizza.should have_a_really_great_sauce end end

Editor's Notes