Rails / RSpec:规范依赖于另一个模型的模型行为?
我正在开发一个 Rails 应用程序,该应用程序跟踪客户详细信息(自然地存储为 Customer
)并使用户能够生成一组客户记录的快照批次 (Batch
) ,基于一组预定义的标准。
Batch
模型负责整理 CSV 的记录,并更新每条记录的状态字段。
我正在努力思考如何使用 RSpec 最好地规范批量生成例程,即 – 消除客户依赖性。
我是否应该创建一组预先确定的客户记录以确保我的规则正确(即,给定记录 a 到 k,该批次不应包括记录 b、d 或 f),或者我是否应该尝试以某种方式模拟/存根它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的决定总是与上下文相关,但是,一般来说,我建议在指定查找器的行为时使用真实模型和数据库。
Decisions like this are always contextual, but, generally speaking, I recommend using real models and the database when specifying behavior of finders.