bcardarella / valid_attribute

Minimalist validation BDD for ActiveModel specs
178 stars 18 forks source link

Make .when optional #8

Closed davisre closed 13 years ago

davisre commented 13 years ago

When I'm specing the boundaries of my validations, I like passing values to #when. Nice and clean. But sometimes I'd prefer to validate an existing object using whatever state it happens to contain, and in these cases .when is either redundant or nonsensical:

thing.should have_valid(:name)
thing.should_not have_valid(:name)

This is especially helpful after some operation that modifies attributes:

thing.strip_whitespace_from_attributes
thing.should have_valid(:email)

In this pull request, I've made #when optional, so have_valid can be used either way. Previously omitting when would raise an exception, but now the matcher uses the existing attribute. I also made a small tweak to wording, to change the phrase "expected foo to not accept the values" to "expected foo to reject the values".

Thanks for a nice, simple gem. I prefer it to "should validate..." style matchers. Test behavior.

bcardarella commented 13 years ago

Makes sense, thanks for the code :) I'll let it sit on master for a few days before releasing a new version.

bcardarella commented 13 years ago

Just released 1.1 with this change

davisre commented 13 years ago

Cool. Thanks.