[rspec-users] Loading (or stubbing) data before model loading

Tom Stuart tom at experthuman.com
Tue Jul 21 15:58:22 EDT 2009


Hi,

A Rails project I'm working on has, for better or worse, some data- 
driven structure in its models: a few model classes need certain  
values (e.g. some enumerations) to be available in the database at  
load time in order for certain bits of metaprogramming to kick off  
correctly. It would be possible to do this all lazily instead of when  
the classes load, but in reality the database values are always there  
and everything already works beautifully so it's hard to justify  
putting in the effort required to be that lazy.

The problem is that RSpec starts with an empty test database and I  
can't see the best way or place to prepopulate it before the models  
get loaded (i.e. when Rails bootstraps, since config.cache_classes =  
true), ideally so that both rake spec and script/spec do the correct  
setup in time. It would be incredibly convenient to be able to use  
Fixtures.create_fixtures to do the loading so that the required data  
can live in YAML fixtures, but maybe it's optimistic to try to do that  
before Rails has loaded.

Or maybe I'm just going about this completely the wrong way, and  
someone has a clever idea about what the right way is? That would be  
brilliant.

Cheers,
-Tom


More information about the rspec-users mailing list