You probably know about this Factory Girl definition syntax:
FactoryGirl.define do
factory :user do
name 'Connie Customer'
end
end
But did you know about this Factory Girl invocation syntax?
setup do
@user = create(:user)
end
Or:
setup do
@user = build(:user)
end
Or:
setup do
post :create, user: attributes_for(:user)
end
It’s in there.
Configuration for Test::Unit / Shoulda:
class ActiveSupport::TestCase
include FactoryGirl::Syntax::Methods
end
Configuration for RSpec:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
Configuration for Cucumber:
World FactoryGirl::Syntax::Methods
Written by Dan Croak.