diff --git a/README.rdoc b/README.rdoc index 682b2ce..11f525c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -205,7 +205,7 @@ Note that every time n is called it will increment, it does not implement a uniq === Reset -Reset all instance variables in the factory. This may be useful to run between tests depending on your factory logic... +Clear all instance variables in the factory. This may be useful to run between tests depending on your factory logic... before(:each) do Factory.reset diff --git a/lib/cranky.rb b/lib/cranky.rb index 928c26d..ddbda40 100644 --- a/lib/cranky.rb +++ b/lib/cranky.rb @@ -1,6 +1,6 @@ class Cranky - VERSION = "0.0.3" + VERSION = "0.0.4" # Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/*.rb").each do |file| # require file @@ -66,7 +66,7 @@ def define(attrs={}) item = get_constant(attrs[:class] ? attrs[:class] : @what.last).new final_attrs.delete(:class) final_attrs.each do |attr, value| - item.send("#{attr}=", value) + item.send("#{attr}=", value) if item.respond_to?("#{attr}=") end item end diff --git a/spec/cranky_spec.rb b/spec/cranky_spec.rb index 846aade..e17ec3c 100644 --- a/spec/cranky_spec.rb +++ b/spec/cranky_spec.rb @@ -72,6 +72,12 @@ error = true end error.should == true + Factory.debug = false + end + + it "should allow arguments to be passed in the overrides hash" do + Factory.build(:user).argument_received.should == nil + Factory.build(:user, :argument_supplied => true).argument_received.should == true end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fba922e..3679cca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,7 @@ class User attr_accessor :role attr_accessor :email attr_accessor :unique + attr_accessor :argument_received def save @saved = true @@ -46,11 +47,13 @@ def user_manually end def user_by_define - define :class => :user, - :name => "Fred", - :role => :user, - :unique => "value#{n}", - :email => "fred@home.com" + u = define :class => :user, + :name => "Fred", + :role => :user, + :unique => "value#{n}", + :email => "fred@home.com" + u.argument_received = true if options[:argument_supplied] + u end alias :user :user_by_define