[rspec-users] Constraints / Global requirements

Pat Maddox pergesu at gmail.com
Wed Jan 7 20:26:25 EST 2009

> From a testing perspective it would be nice if cucumber could actually run
> the date validation feature everywhere it applies.

Sure, and you can have a step like

Given birth date is valid

Given /(.*) date is valid/ do |field|
  TestData.valid_dates.each do |date|
    @it.send "#{field}_date=", date
    @it.should be_valid

  TestData.invalid_dates.each do |date|
    @it.send "#{field}_date=", date
    @it.should_not be_valid

That gets you technical validation everywhere you need it.  Then you
have another individual feature file that describes date formats.

> P.S. Date validation really isn't that important in my application; that's
> just an example.  A real example would be the sales tax calculation in the
> leasing app I worked on.  That was very important, it was a global
> requirement with some important exceptions.  But I think your approach would
> have worked there as well.

Same ideas apply.


p.s. I didn't realize you were also the author of the other thread I
linked to :)

More information about the rspec-users mailing list