Your SlideShare is downloading. ×
BDD for Ruby
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

BDD for Ruby

1,788
views

Published on

The slides in Ruby Tuesday 3/10 Taiwan.

The slides in Ruby Tuesday 3/10 Taiwan.

Published in: Technology

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

No Downloads
Views
Total Views
1,788
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
57
Comments
0
Likes
4
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. Behavior Driven Development for Ruby Lu Wei Jen
  • 2. TDD vs. BDD
  • 3. TDD
    • Test Driven Development
    • Writing tests before writing the code being tested.
    • Red/Green/Refactor
  • 4.  
  • 5. TDD 缺點
    • 怎麼開始?
    • 為測試而測試
    • 容易失焦,然後就放棄
  • 6. BDD
    • Behavior Driven Development
    • 用一句簡單的句子或字彙來描述功能,以減低參與者的誤解。
    • 描述你 要做什麼 ,而不是你 怎麼作 。
    • Getting the word right was the starting point for the development of BDD.
    • BDD是用來加強TDD,而非取代TDD。
  • 7. BDD methods
    • 用一個句子來描述你的測試內容。
    • 用簡單的文法(sentence template)讓你的測試不失焦。
    • 描述行為,而不是描述測試
  • 8. BDD tools for ruby
    • Cucumber
    • RSpec
  • 9. Cucumber
  • 10. Cucumber
    • Home: http://cukes.info/
    • GitHub: http://github.com/aslakhellesoy/cucumber/
    • Install
      • git clone git://github.com/aslakhellesoy/cucumber.git
      • sudo rake install_gem
  • 11. Features Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers Scenario Outline: Add two numbers Given I have entered <input_1> into the calculator And I have entered <input_2> into the calculator When I press <button> Then the result should be <output> on the screen Examples: | input_1 | input_2 | button | output | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
  • 12. 你也可以寫中文 功能 : 加法 為了避免愚蠢的錯誤 作為一個數學白痴 我希望有人能告訴我兩個數相加的結果 場景大綱 : 將兩個數相加 假設 我已經在計算機上輸入 < 數值 _1> 而且 我已經在計算機上輸入 < 數值 _2> 當 我按下 < 按鈕 > 那麼 螢幕上應該顯示 < 結果 > 例子 : | 數值 _1 | 數值 _2 | 按鈕 | 結果 | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
  • 13. Cucumber Keywords feature: 功能 background: 背景 scenario: 場景|劇本 scenario_outline: 場景大綱|劇本大綱 examples: 例子 given: 假設 when: 當 then: 那麼 and: 而且|並且 but: 但是
  • 14. RSpec
    • Home: http://rspec.info/
    • GitHub: http://github.com/dchelimsky/rspec
    • Install: sudo gem install rspec
  • 15. Rspec Example describe Calculator do context &quot; 將兩個數相加 &quot; do before(:each) do @calculator = Calculator.new end it &quot; 應該有一個數字已經輸入 &quot;do @calculator.push.should an_instance_of(Fixnum) end end end
  • 16. M Working from the Outside-In
  • 17. BDD Step with Cucumber and RSpec
  • 18. Example
    • User Story
      • 客戶端在確認與遠端伺服器連線狀態,並登入後,則取回廣告內容。
    • Actor
      • 客戶端
      • 遠端伺服器
    • Behaviour(for client)
      • 確認連線狀態
      • 登入
      • 取回廣告內容
  • 19. Example: feature 功能 : 連線確認 為了避免無意義的資料擷取動作, 如果我是客戶端電腦, 我會先確認是否與遠端伺服器連線 劇本 : Ping遠端伺服器 假設 我被告知需要向遠端伺服器取得資料 當 我對遠端伺服器發出ping的要求 那麼 遠端伺服器會回傳pong
  • 20. Example: Passing Feature
  • 21. Example: Step Definitions
    • 你在劇本中的步驟
    • 在這裡,關鍵字還不能寫中文
  • 22. Example: RSpec
    • 先利用劇本中的步驟作為大標題
    • 在這個步驟中你需要測試甚麼?
  • 23.
      • Q and A