2010-07-14 27 views
0

我想使用黃瓜來測試我的Rails應用程序的用戶的年齡。功能定義看起來有點像以下。自動測試用戶的年齡每年都會失敗

Scenario: Successful calculation of age 
    Given I set my date of birth to "1987-07-15" 
    Then my age should be "22" 

上面的功能定義每年都會失敗,因爲用戶的年齡會每年增加一個。

一種解決方案可能是將出生日期動態設置爲22.years.ago。但我不知道如何在Gherkin(黃瓜特徵定義語言)中做到這一點。

對此有何看法?

回答

4

我想補充與此類似

Scenario: Successful calculation of age 
    Given I set my date of birth to "1987-07-15" And the Date is "15/07/2010" 
    Then my age should be "22" 
2

另一個給定的條件,您可以只寫

Scenario: Successful calculation of age 
Given I set my date of birth to "22" years ago 
Then my age should be "22" 

,做自己基於第一22日期轉換(例如有一個Fixnum參數,以此來測試方法而不是日期)。但說實話我可能會選擇伊恩的方法。