I’ve been reading the Learn app from thoughtbot code and I notice that in most specs the spec_helper is added to it; why is this necessary if in most cases the spec just need something that act as it’s the class under test. Looking at the specs for app/services and app/decorators in here.
It’s seems to me that not adding spec_helper for all the specs that doesn’t need it it will improve dramatically the speed of the test.
Can somebody explain to me this decision? Of course it should be somebody from thoughtbot
Some people have a set of fast tests that either don’t require the whole Rails environment or don’t require a database connection, etc., and they will have leaner versions of spec helper (usually subsets of the code loaded in spec_helper) that get loaded instead. I generally find that to be too much effort to maintain, and try to get around the load time issue with something like Spring and avoiding DB access in tests whenever it’s not absolutely necessary.
FYI, if you want to see a pretty interesting example of separate spec helpers depending on the weight of the system under test’s dependencies, check out Avdi Grim’s Objects on Rails: http://objectsonrails.com/
Well, what I mean is just to require the class under test file directly from within my spec and not having a separate spec_helper for those; because normally that’s only Ruby code that’s how I’ve been doing it. It doesn’t need any other dependency or that’s what I aim for.
Regarding my models I do try to use another spec_helper which just load activerecord because normally I don’t need Rails to test an AR model.