ruby-on-rails – 当我使用Spork时,如何确保帮助程序和模型在RSpec中重新加载?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 当我使用Spork时,如何确保帮助程序和模型在RSpec中重新加载?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
似乎我的助手(有时是我的模型)在Spork的每次运行中都没有被重新加载.我应该把什么放进我的“Spork.each_run”区块?

解决方法

我遇到了同样的问题,所以我在each_run块中设置了它:
Spork.each_run do
  # This code will be run each time you run your specs.
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
  FactoryGirl.reload

  Dir[File.join(File.dirname(__FILE__),'..','app','helpers','*.rb')].each do |file|
    require file
  end
end

另外,请不要忘记在config / environments / test.rb中:

config.cache_classes = !(ENV['DRB'] == 'true')
原文链接:https://www.f2er.com/ruby/269683.html

猜你在找的Ruby相关文章