Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created July 14, 2011 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmaddox/1083369 to your computer and use it in GitHub Desktop.
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
# 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