Hello,
i’ve an initializer which set as constants all the instances retrieved
from the DB, for specific AR models.
Thoose constant are used a bit everywhere in the application.
In my unit test, I run the initializer top preload my “dynamic
constants” in the setup method of the test class. The setup method call
a method in the test_helper class, as follows :
require File.dirname(FILE) + ‘/…/test_helper’
class StatusTest < ActiveSupport::TestCase
setup :preload_constants_from_db
(…)
end
In the test_helper file I got the method preload_constants_from_db,
which require the initializer.
def preload_constants_from_db
require File.expand_path(File.dirname(FILE) +
“/…/config/initializers/constant_cache”)
end
Run separately the test works great :
mac:trunk nico$ ruby test/unit/status_test.rb
Loaded suite test/unit/status_test
Started
…
Finished in 0.955416 seconds.
4 tests, 5 assertions, 0 failures, 0 errors
mac:trunk nico$ ruby test/unit/status_test.rb
Loaded suite test/unit/status_test
Started
…
Finished in 0.958518 seconds.
4 tests, 5 assertions, 0 failures, 0 errors
But run whith rake everything fails :
rake test:units
=> BOUM
Any idea how to proceed ??
PS: Sorry for the approximative english…