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

#8 - defining an attribute ending with = raises an error (thanks to the Boston.rb hackfest)

This commit is contained in:
Joe Ferris 2008-07-29 16:45:39 -04:00
commit 6469e9b4d9
2 changed files with 19 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 = {}
@ -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"

View file

@ -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