sporkrb / spork

A DRb server for testing frameworks (RSpec / Cucumber currently) that forks before each run to ensure a clean testing state.
spork.rubyforge.org
MIT License
1.4k stars 202 forks source link

Reloading models each run causes duplicates errors on models #141

Open Dagnan opened 13 years ago

Dagnan commented 13 years ago

First, spork -d shows only config files so models are not preloaded. I'm also using Spork with Test:Unit (actually Minitest, last version from Rubygems), Rails 3 (with Spork last rc) and Ruby 1.9.2.

I had to put a load instruction for all my models in Spork#each_run because not all files under /app/models where loaded (I have subdirectories).

But the behavior I get is when my models is invalid, errors are duplicates:

foo = Foo.new(:bar => '').valid? #=> false
foo.errors #=> {:bar => ["can't be blank", "can't be blank"]}

For now if I reload only models from /models subdirectories I get the expected behavior. But this is kind of ugly.

nofxx commented 13 years ago

Had the same issue here. Tryed every jujitso/workaround/patch myself thing to make spork 0.8.5 work w/o luck. That one ([Rails.root, 'models/*.].each(&load.....) I call the load'em all, and its a bad idea! You'll get that double errors and plus some other glitches with "cache_classes = true" in test enviroment (fabrication and machinist don't behave nicely that way).

Try spork 0.9.0.rc9, it's all working perfect here, models reloading and no bugs, I dunno why (yet, just found out heh). Just did the trap load_models of mongoid.

Dagnan commented 13 years ago

I'm already using 0.9.0.rc9 :/

nofxx commented 13 years ago

Oh, sorry Dagnan, missed the "spork last rc".
Here's my spec_helper: https://gist.github.com/1289242

Just to confirm: that's finally reloading my models and no glitches in rails 3.1.1, with cache_classes = true. (besides bugs, cache_classes = false makes my 30s suite take 2:00 to run! major pita.