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

Don't require a block to be passed when defining a factory

This commit is contained in:
Joshua Clayton 2011-06-29 14:43:15 -04:00
parent 90ea1fe304
commit 4d8d419375
9 changed files with 25 additions and 17 deletions

View file

@ -15,7 +15,7 @@ module FactoryGirl
def factory(name, options = {}, &block)
factory = Factory.new(name, options)
proxy = FactoryGirl::DefinitionProxy.new(factory)
proxy.instance_eval(&block)
proxy.instance_eval(&block) if block_given?
if parent = options.delete(:parent)
factory.inherit_from(FactoryGirl.factory_by_name(parent))
end

View file

@ -10,8 +10,7 @@ describe "attribute aliases" do
end
FactoryGirl.define do
factory :user do
end
factory :user
factory :post do
user

View file

@ -15,8 +15,7 @@ describe "a generated attributes hash" do
end
FactoryGirl.define do
factory :user do
end
factory :user
factory :post do
title { "default title" }

View file

@ -12,8 +12,7 @@ describe "a built instance" do
end
FactoryGirl.define do
factory :user do
end
factory :user
factory :post do
user

View file

@ -14,8 +14,7 @@ describe "a generated stub instance" do
end
FactoryGirl.define do
factory :user do
end
factory :user
factory :post do
title { "default title" }

View file

@ -12,8 +12,7 @@ describe "a created instance" do
end
FactoryGirl.define do
factory :user do
end
factory :user
factory :post do
user

View file

@ -6,8 +6,7 @@ describe "default strategy" do
define_model('User')
FactoryGirl.define do
factory :user do
end
factory :user
end
Factory(:user).should_not be_new_record
@ -17,8 +16,7 @@ describe "default strategy" do
define_model('User')
FactoryGirl.define do
factory :user, :default_strategy => :build do
end
factory :user, :default_strategy => :build
end
Factory(:user).should be_new_record

View file

@ -6,8 +6,7 @@ describe "an instance generated by a factory with a custom class name" do
define_model("User", :admin => :boolean)
FactoryGirl.define do
factory :user do
end
factory :user
factory :admin, :class => User do
admin { true }

View file

@ -0,0 +1,16 @@
require 'spec_helper'
require 'acceptance/acceptance_helper'
describe "an instance generated by a factory" do
before do
define_model("User")
FactoryGirl.define do
factory :user
end
end
it "registers the user factory" do
FactoryGirl.factory_by_name(:user).should be_a(FactoryGirl::Factory)
end
end