Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spork won't reload file in lib

I'm running rspec with spork and I can't get a file in lib to reload on consecutive rspec runs. I've tried require'ing the file in 'Spork.each_run'

I'm not getting any responses, so I'll try to explain further. I have the following files in my Rails app:

  • lib/car.rb
  • spec/lib/car_spec.rb

To run tests, first I start spork then run 'rspec spec/lib/car_spec.rb'

RSpec is not seeing my changes to my Car class, unless I restart spork.

Any help?

I'm on:

  • rails 3.1.0.rc6
  • rspec 2.6.0
  • spork 0.9.0.rc9
like image 936
Austin Avatar asked Aug 27 '11 04:08

Austin


2 Answers

Try to load that file in Spork.each_run instead of require.

like image 82
Victor Deryagin Avatar answered Nov 12 '22 09:11

Victor Deryagin


I hear you. Reloading of files in lib/ is very important.

When I do a require directly (e.g. require "some_dir_under_lib/some_file"), it doesn't get reloaded automatically. However, if I do

Dir["some_dir_under_lib/*.rb"].each { |file| require file }

then it DOES get reloaded automatically! I wish I could explain why!

Btw, I'm doing that in application.rb, not in spork/spec_helper stuff.

like image 43
Tyler Collier Avatar answered Nov 12 '22 11:11

Tyler Collier