So, I’ve been working on a project for my new workplace, and because of all the dependencies (which are all necessary - I checked), the test suite itself takes 6-7 seconds just to boot up.
My normal workflow on smaller projects is to have
guard running, and then use TDD to drive the design of the application. This works pretty well, because on a smaller application, it only takes 1 second or so to run the test file.
However, when working with this current application - it’s taking 6-7 seconds between each save - which deters me from doing true TDD (I end up doing Test First Design instead - which isn’t the goal).
I realize that the issue of speed is because of including
spec_helper), which include the Rails stack and the application’s dependencies.
So - all in all, I guess my question is:
What is the best way to create fast tests when needing to test classes that are dependent on Objects that inherit from ActiveRecord?
- Models with Associations
- Service classes that use ActiveRecord Objects
Is that just the pain of testing Rails Models? Or should I be pulling out all business logic into Modules/Classes?
Those classes that are services, should I just be injecting the ActiveRecord object into the initialize function - so that I can send in a stub within the test?