Created
July 14, 2011 20:31
-
-
Save patmaddox/1083369 to your computer and use it in GitHub Desktop.
A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A goofy bit of code that takes your shoulda-style macro validations and generates a model class from it | |
require 'rspec' | |
require 'active_model' | |
module ActiveRecordTranslator | |
def it_should_validate_presence_of(field) | |
klass = Class.new do | |
include ActiveModel::Validations | |
attr_reader field | |
validates field, :presence => true | |
end | |
eval "::#{description} = klass" | |
end | |
end | |
describe "User" do | |
extend ActiveRecordTranslator | |
it_should_validate_presence_of :name | |
it "validates the name" do | |
user = User.new | |
user.should_not be_valid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment