Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spork doesn't reload code

I am using following gems and ruby-1.9.3-p194:

  • rails 3.2.3

  • rspec-rails 2.9.0

  • spork 1.0.0rc2

  • guard-spork 0.6.1

Full list of used gems is available in this Gemfile.lock or Gemfile.

And I am using this configuration files:

  • Guardfile

  • .rspec

  • spec_helper.rb

  • factories.rb

If I modify any model (or custom validator in app/validators etc) reloading code doesnt works.

I mean when I run specs (hit Enter on guard console) Spork contain "old code" and I got obsolete error messages. But when I manually restart Guard and Spork (CTRC-C CTRL-d guard) everything works fine. But it is getting tired after few times.

Questions:

Can somebody look at my config files please and fix error which block updating code.

Or maybe this is an issue of newest Rails version?


PS This problem repeats and repeats over some projects (and on some NOT). But I haven't figured out yet why this is happens.

PS2 Perhaps this problem is something to do with ActiveAdmin? When I change file in app/admin code is reloaded.

like image 764
nothing-special-here Avatar asked Apr 24 '12 09:04

nothing-special-here


3 Answers

Workaround:

# config/environments/test.rb
config.cache_classes = false

But it is "double-edged sword".

Specs run now ~2.0x time longer. But it is still faster than restarting again and again Spork.


Update 28.06.2013

Use Zeus. It works perfectly. Benchmarks are at the bottom..

If you are using 1.9.3 consider installing special patches which REALLY speed up loading app.

RVM patchsets

rbenv instructions

Background & Benchmark:

I have a quite large 1.9.3 app and I wanted to speedup app loading, Spork doesn't work so I started looking for other solutions:

I write a empty spec to see how long it takes to load my app

-/spec/empty_spec.rb

require 'spec_helper'

describe 'Empty' do

end

plain 1.9.3

time rspec spec/empty_spec.rb 64,65s user 2,16s system 98% cpu 1:07,55 total

1.9.3 + rvm patchsets

time rspec spec/empty_spec.rb 17,34s user 2,58s system 99% cpu 20,047 total

1.9.3 + rvm patchsets + zeus

time zeus test spec/empty_spec.rb 0,57s user 0,02s system 58% cpu 1,010 total [w00t w00t!]

like image 70
nothing-special-here Avatar answered Nov 02 '22 11:11

nothing-special-here


Alternatively, you can add guards for your models, controllers and other code. It'll make guard reload spork when any of these files change.

guard 'spork',
      :rspec_env => {'RAILS_ENV' => 'test'} do
  watch(%r{^app/models/(.+)\.rb$})
  watch(%r{^lib/(.+)\.rb$})
end
like image 7
Sergio Tulentsev Avatar answered Nov 02 '22 10:11

Sergio Tulentsev


I had the same problem. Tests were reloaded and ran successfully for changes to model_spec.rb. When I made changes to the model.rb file the tests were re-run, however the code seemed to be cached - so the changed were not applied.

It required a combination of a few answers to get things working:

# /config/environments/test.rb
config.cache_classes = !(ENV['DRB'] == 'true')

# spec_helper.rb
Spork.each_run do
  .....
  ActiveSupport::Dependencies.clear
end

I also updated spork to (1.0.0rc3) and replaced the spork gem with spork-rails, as mentioned by @23inhouse above. However, I did not see any difference between either gem in the gemfile although upgrading spork may have had an effect.

Hopefully this helps someone else not spend any more hours banging their head against the wall.

like image 5
yellowaj Avatar answered Nov 02 '22 11:11

yellowaj