Reload RSpec common examples with Guard and Spork

How do I get spork to reload my common examples when I make changes to them? I tried the following but did not restart them:

Spork.each_run do
  Dir[Rails.root.join("spec/shared_examples/*.rb")].each {|f| require f}
end

I know that I can add an observer to my Guardfile so that it reloads env when changing common examples, but my application is large and takes about 10-15 seconds to reload the whole environment:

watch(/^spec\/shared_examples\/.*\.rb$/)

I would rather just reload the generic examples that have changed, so I can have a faster feedback loop.

+3
source share
3 answers

, shared_examples Spork.prefork - , . Spork.prefork Spork.each_run , shared_examples .

+3

, :

test.rb ,

  config.cache_classes = !(ENV['DRB'] == 'true')

, , Spork.

, .each_run

FactoryGirl.reload
ActiveSupport::Dependencies.clear
ActiveRecord::Base.instantiate_observers

, .

share_examples .each_run.

Spork.each_run do
  FactoryGirl.reload
  ActiveSupport::Dependencies.clear
  ActiveRecord::Base.instantiate_observers
  Dir[Rails.root.join("spec/shared_examples/*.rb")].each {|f| require f}  
end

4 .each_run, , .

+8
Spork.prefork do
  Dir[Rails.root.join("spec/shared_examples/*.rb")].each {|f| require f}
end
0
source

All Articles