1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Raise AttributeDefinitionError when defining an attribute with f.attr=value rather than f.attr value; ticket #8

This commit is contained in:
thoughtbot 2008-07-22 19:46:01 -04:00
parent edd39c652c
commit 6c49c69cd8
2 changed files with 16 additions and 1 deletions

View file

@ -1,5 +1,8 @@
class Factory
class AttributeDefinitionError < RuntimeError
end
cattr_accessor :factories, :sequences #:nodoc:
self.factories = {}
self.sequences = {}
@ -93,6 +96,10 @@ class Factory
# value: (Object)
# If no block is given, this value will be used for this attribute.
def add_attribute (name, value = nil, &block)
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"

View file

@ -52,6 +52,14 @@ class FactoryTest < Test::Unit::TestCase
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
setup do