I’m working on a Rails application that tracks customer details (stored as a Customer, naturally) and enables users to generate snapshot batches (Batch) of a set of customer records, based on a set of pre-defined criteria.
The Batch model is responsible for collating records for a CSV, as well as updating a status field of each record.
I’m struggling to get my head around how to best spec the batch generation routines using RSpec, namely – stubbing the Customer dependency.
Should I be creating a pre-determined set of Customer records that I can use to ensure my rules are correct (ie, given records a through k, this batch should not include records b, d or f), or should I be attempting to mock/stub them out somehow?
Decisions like this are always contextual, but, generally speaking, I recommend using real models and the database when specifying behavior of finders.