thoughtbot--factory_bot/spec
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
..
acceptance Introduce new callback syntax 2012-05-04 17:59:34 -04:00
factory_girl Introduce new callback syntax 2012-05-04 17:59:34 -04:00
support Move strategy calculation to Factory#run 2012-05-04 13:36:46 -04:00
factory_girl_spec.rb Clean up attribute and core factory specs 2011-08-19 17:21:14 -04:00
spec_helper.rb Clean up SimpleCov usage 2012-04-23 21:50:39 -05:00