I just released a new gem on GitHub that provides some common validation expectations to rspec. Instead of writing specs to verify that your models are handling validation correctly, these expectations simply check that the validation is getting declared correctly in your model. For example:
describe User do it_should_validate_presence_of :first_name, :last_name, :email it_should_validate_numericality_of :zip it_should_validate_uniqueness_of :email end
Since the expectations never hit the database, they are also faster than testing the traditional way. It’s dead simple to install on Rails 2.1 or later:
script/plugin install git://github.com/pelargir/rspec_validation_expectations.git
The expectations become available to your specs immediately.
Comments
One response to “rspec_validation_expectations gem released”
[…] rspec_validations_expectations gem released – Check that your models contain the validations you want, without hitting the database to test Rails-generated code. […]