def model_factory_helper(calling_spec, model_class, options)
raise "factory_method requires default_attributes" unless options.has_key?(:default_attributes)
raise "factory_method default_attributes must be a Hash" unless options[:default_attributes].is_a?(Hash)

proper_class_name = model_class.name
lowered_class_name = model_class.name.downcase

calling_spec.instance_eval <<-"end;"
module #{proper_class_name}HelperFactory

def #{lowered_class_name}_default_attributes(options = {})
#{options[:default_attributes].inspect}.merge(options)
end

def #{lowered_class_name}_with(options = {})
options = {} if options == :all
#{proper_class_name}.new(#{lowered_class_name}_default_attributes(options))
end

def #{lowered_class_name}_without(field)
#{proper_class_name}.new(#{lowered_class_name}_default_attributes(field => nil))
end

def it_should_require_fields(*fields)
fields.each do |field|
it "should require \#{field}" do
#{lowered_class_name}_without(field).should_not be_valid
end
end
end
end

include #{proper_class_name}HelperFactory
end;
end