views:

68

answers:

2

I want to test the age of a user of my Rails application using cucumber. The feature definition look somewhat like following.

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

Above feature definition will fail every year since the age of user will increase by one each year.

One solution could be to set the date of birth dynamically to something like 22.years.ago. But I do not know how to do this in Gherkin(cucumber feature definition language).

Any take on this?

+4  A: 

I would add another given condition similar to this

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"
Iain
+2  A: 

You could just write

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

And do the date conversion yourself based on the first 22 (e.g. have a Fixnum parameter to your test method instead of a date). But to be honest I'd probably go for Iain's method.

Grant Crofton