Skip to content

Commit

Permalink
Now allows parameter passing to factory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginty committed May 23, 2010
1 parent f72a080 commit 340b093
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/cranky.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/cranky_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class User
attr_accessor :role
attr_accessor :email
attr_accessor :unique
attr_accessor :argument_received

def save
@saved = true
Expand Down Expand Up @@ -46,11 +47,13 @@ def user_manually
end

def user_by_define
define :class => :user,
:name => "Fred",
:role => :user,
:unique => "value#{n}",
:email => "[email protected]"
u = define :class => :user,
:name => "Fred",
:role => :user,
:unique => "value#{n}",
:email => "[email protected]"
u.argument_received = true if options[:argument_supplied]
u
end
alias :user :user_by_define

Expand Down

0 comments on commit 340b093

Please sign in to comment.