From: leah@... Date: 2007-06-22T05:40:12+09:00 Subject: Unit Testing Custom Validation Method Hey there I've written a custom validation method (to validate an email address). It looks like module ActiveRecord module Validations module ClassMethods def validates_as_email ... end end end end I've put this code in app/lib/custom_validations.rb Now, I'm trying to write a unit test but I'm running into problems. One attempt at a unit test looks like require File.dirname(__FILE__) + '/../test_helper' require 'lib/custom_validations' class CustomValidationsTest < Test::Unit::TestCase def test_validates_as_email email = "someone@example.com" assert validates_as_email( email ) end end This throws a NoMethodError: undefined method `validates_as_email' for # It looks to me like the test is looking for the validates_as_email method to be defined in CustomValidationsTest rather than finding it in lib/custom_validations.rb So, I tried this require File.dirname(__FILE__) + '/../test_helper' require 'lib/custom_validations' class CustomValidationsTest < Test::Unit::TestCase def test_validates_as_email email = "someone@example.com" assert ActiveRecord::Validations::ClassMethods.validates_as_email( email ) end end And I got this error NoMethodError: undefined method `validates_as_email' for ActiveRecord::Validations::ClassMethods:Module What am I missing? I'll bet it's something simple, but I just can't figure out what's wrong. Thanks for the help.