Wrap text
Report abuse
In my test_helper.rb
|
|
class Test::Unit::TestCase
def self.klass
self.name.chomp("Test")
end
def self.creator(options={})
define_method("create_#{self.klass.underscore}") {|*args|
opts = args.first || {}
klass.constantize.create(options.merge(opts)) }
end
def self.default_creation_test
define_method("test_should_create_#{klass.underscore}") {
assert_difference klass.constantize, :count do
object = send("create_#{self.klass.underscore}")
assert !object.new_record?, "#{object.errors.full_messages.to_sentence}"
end
}
end
def self.erroneous_creation_test(field, value)
define_method("test_should_not_create_on_erroneous_#{field.to_s}") {
assert_no_difference klass.constantize, :count do
object = send("create_#{self.klass.underscore}", {field => value})
assert_not_nil object.errors.on(field)
end
}
end
# ...
end
|