E.g.:

Factory.define :user do |user|
  user.name  { Faker::Name.name }
  user.admin false
end

Example specs:

it 'something that has to do with an admin' do
  admin = Factory :user, :admin => true
  admin.should foobar
end

it 'something to do with a regular user'
  user = Factory :user
  user.should foobar
end

Why and how is this done better by Machinist? Whatever needs to be
overriden in FG, you can just throw in the second argument (a Hash).

ps: honest question, I haven't given Machinist a serious go, and
perhaps I should. But FG always covered my needs.


On Wed, Apr 21, 2010 at 1:50 PM, Ryan Bigg <radarliste...@gmail.com> wrote:
> I should clarify what I mean by syntax, sorry. By syntax I mean that in
> factory_girl you can do this to define a named factory:
> Factory.define :admin, :class => User do |u|
>   u.admin               true
> end
> This gives you access to Factory(:admin). But now think about it like this:
> say you want to set up a three-level relationship between Account, Project
> and Tickets. You want to create three different setups for testing. To do
> this in Factory Girl, you'd have to do:
> Factory.define :one, :class => Account do |a|
>   a.name "Blah"
> end
> And then you *could try* to do:
> Factory.define :one, :class => Project do |p|
> But you'd be overriding the first Factory. You'd instead have to call it
> something like account_one and project_one, which is just fugly.
> In Machinist however, named blueprints are done on the class so you CAN
> define a blueprint with the same name for two different classes:
> Account.blueprint(:one) do
>   name "Blah"
> end
> Project.blueprint(:one) do
>   name "Longest project ever."
> end
> And that, is why I love Machinist.
>
>
> On 21 April 2010 13:39, Pat Allan <p...@freelancing-gods.com> wrote:
>>
>> Agreed - I find the syntax of Machinist to be far nicer than Factory Girl.
>> And there are some *awesome* improvements coming in Machinist v2.
>>
>> --
>> Pat
>>
>> On 21/04/2010, at 1:30 PM, Ryan Bigg wrote:
>>
>> > Another +1 to Machinist, use it everywhere. Not because Pete is awesome,
>> > but I prefer the syntax for defining named blueprints over named factories.
>> >
>> > On 21 April 2010 13:13, Julian Doherty <julian.doherty...@gmail.com>
>> > wrote:
>> > Using machinist for a few projects at the moment (mainly because it's
>> > pretty useful, not just cause Pete Yandell would give me a disapproving
>> > sneer if I didn't :P )
>> >
>> >
>> > On 21 April 2010 12:59, Jonathan Clarke <jonat...@beilabs.com> wrote:
>> > At Railscamp I think he mentioned that he was working on Machinist 2,
>> > looking forward to checking it out!
>> >
>> > Jonathan
>> >
>> >
>> > On 21 April 2010 12:55, James Healy <ji...@deefa.com> wrote:
>> > Jono wrote:
>> > > Does anyone know if there any significant differences between the two
>> > > libraries apart from syntax that make one stand out from the other?
>> >
>> > There's at least one significant difference, Machinist is by Pete
>> > Yandell ('our Pete').
>> >
>> > Piffle at technical merits, buy Australian! :)
>> >
>> > -- James Healy <ji...@deefa.com>  Wed, 21 Apr 2010 12:53:27 +1000
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Ruby or Rails Oceania" group.
>> > To post to this group, send email to rails-ocea...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rails-oceania+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/rails-oceania?hl=en.
>> >
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Ruby or Rails Oceania" group.
>> > To post to this group, send email to rails-ocea...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rails-oceania+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/rails-oceania?hl=en.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Ruby or Rails Oceania" group.
>> > To post to this group, send email to rails-ocea...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rails-oceania+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/rails-oceania?hl=en.
>> >
>> >
>> >
>> > --
>> > Ryan Bigg / Radar
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Ruby or Rails Oceania" group.
>> > To post to this group, send email to rails-ocea...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rails-oceania+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/rails-oceania?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby or Rails Oceania" group.
>> To post to this group, send email to rails-ocea...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> rails-oceania+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/rails-oceania?hl=en.
>>
>
>
>
> --
> Ryan Bigg / Radar
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> To post to this group, send email to rails-ocea...@googlegroups.com.
> To unsubscribe from this group, send email to
> rails-oceania+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rails-oceania?hl=en.
>



-- 
http://crazyhollywood.org

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to rails-ocea...@googlegroups.com.
To unsubscribe from this group, send email to 
rails-oceania+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to