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:
parent
90ea1fe304
commit
4d8d419375
9 changed files with 25 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -10,8 +10,7 @@ describe "attribute aliases" do
|
|||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
end
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
user
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -12,8 +12,7 @@ describe "a built instance" do
|
|||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
end
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
user
|
||||
|
|
|
@ -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" }
|
||||
|
|
|
@ -12,8 +12,7 @@ describe "a created instance" do
|
|||
end
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :user do
|
||||
end
|
||||
factory :user
|
||||
|
||||
factory :post do
|
||||
user
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
|
16
spec/acceptance/definition_without_block_spec.rb
Normal file
16
spec/acceptance/definition_without_block_spec.rb
Normal 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
|
Loading…
Reference in a new issue