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

6 commits

Author SHA1 Message Date
Joshua Clayton
b095f24598 Convert to expect syntax 2013-01-18 13:58:36 -05:00
Josh Clayton and Jason Draper
bef5a01b31 Introduce new callback syntax
Instead of calling before_create, after_build, after_create, or
after_stub, you can now call:

    before(:create) {|instance| instance.name = "overridden!" }
    after(:create)  {|instance| instance.name = "overridden!" }
    after(:build)   {|instance| instance.name = "overridden!" }
    after(:stub)    {|instance| instance.name = "overridden!" }

Additionally, you can declare callbacks longhand:

    callback(:after_stub) {|instance| instance.name = "overridden!" }

This allows for custom callbacks to be defined:

    callback(:custom_callback) {|instance| instance.name = "overridden!" }

Which can then be used from a custom strategy:

    class CustomStrategy
      def association(runner); end

      def result(evaluation)
        evaluation.object.tap do |instance|
          evaluation.notify(:custom_callback, instance)
        end
      end
    end

    FactoryGirl.register_strategy(:custom, CustomStrategy)

This would allow for calling:

    FactoryGirl.custom(:user)

Which would return the user instance but execute the :custom_callback callback
on the user instance first.
2012-05-04 17:59:34 -04:00
Joshua Clayton
dc81590a4c Change lambda {}.should to expect {}.to 2012-04-20 16:58:26 -04:00
Joshua Clayton
6c29b11477 Use 1.9 hash syntax 2012-03-16 16:43:23 -04:00
Joshua Clayton
7fdf1a8858 Registries are named
This allows for easier debugging when code attempts to access traits,
sequences, or factories and doesn't find what it was looking for.

Closes #212
2011-10-15 02:01:16 -04:00
Stephan Eckardt and Josh Clayton
14b8245371 Allow factories to be modified after they've been defined.
This adds `FactoryGirl.modify`, which allows for reopening of factories
that've been defined elsewhere. Modifying a factory won't remove or
change callbacks, only attributes.
2011-09-02 12:05:44 -04:00