Skip callbacks on Factory Girl and Rspec

前端 未结 16 1010
暗喜
暗喜 2020-12-12 12:17

I\'m testing a model with an after create callback that I\'d like to run only on some occasions while testing. How can I skip/run callbacks from a factory?

c         


        
16条回答
  •  离开以前
    2020-12-12 12:51

    None of these solutions are good. They deface the class by removing functionality that should be removed from the instance, not from the class.

    factory :user do
      before(:create){|user| user.define_singleton_method(:send_welcome_email){}}
    

    Instead of suppressing the callback, I am suppressing the functionality of the callback. In a way, I like this approach better because it is more explicit.

提交回复
热议问题