Reload factory_girl factory

后端 未结 2 1553
走了就别回头了
走了就别回头了 2021-02-19 10:50

I want that when I make changes in factories, I see them in rails console without restarting all console.

I\'ve found some lines and tested them with a poor understandin

2条回答
  •  伪装坚强ぢ
    2021-02-19 11:23

    You can also use reload! to reload the console environment but it doesn't reload the factories. Use FactoryGirl.reload to reload the Factory definitions. It (re)loads those definitions from the following locations (see the documentation):

    test/factories.rb
    spec/factories.rb
    test/factories/*.rb
    spec/factories/*.rb
    

    The other commands you mention are used to clear and load the definitions. FactoryGirl.factories.clear clears all loaded Factory definitions, while FactoryGirl.find_definitions reloads all definitions from file.

    Be sure to use the factory_girl_rails gem if your on Rails. When you've for example defined a factory :user, you can use it in your console with FactoryGirl.build(:user) or FactoryGirl.create(:user). This will return a User instance.

    If that doesn't work, please post some more details.

提交回复
热议问题