diff --git a/lib/factory_girl/factory.rb b/lib/factory_girl/factory.rb index f969fb4..66f1a9a 100644 --- a/lib/factory_girl/factory.rb +++ b/lib/factory_girl/factory.rb @@ -1,5 +1,8 @@ class Factory - + + class AttributeDefinitionError < RuntimeError + end + cattr_accessor :factories, :sequences #:nodoc: self.factories = {} self.sequences = {} @@ -94,6 +97,13 @@ class Factory # If no block is given, this value will be used for this attribute. def add_attribute (name, value = nil, &block) name = name.to_sym + + if name.to_s =~ /=$/ + raise AttributeDefinitionError, + "factory_girl uses 'f.#{name.to_s.chop} #{value}' syntax " + + "rather than 'f.#{name} #{value}'" + end + if block_given? unless value.nil? raise ArgumentError, "Both value and block given" diff --git a/test/factory_test.rb b/test/factory_test.rb index 64cad57..91a9eaf 100644 --- a/test/factory_test.rb +++ b/test/factory_test.rb @@ -52,6 +52,14 @@ class FactoryTest < Test::Unit::TestCase end end + + should "raise an error when defining a factory when using attribute setters" do + assert_raise Factory::AttributeDefinitionError do + Factory.define(:user) do |f| + f.name = 'test' + end + end + end context "defining a sequence" do