我已经在RoR开发了一年多了,但我刚刚开始使用RSpec进行测试.
对于标准模型/控制器测试,我通常没有任何问题,但问题是我想测试一些复杂的功能过程,并且不知道如何构建我的测试文件夹/文件/数据库.
这是我的应用程序的基本结构:
class Customer
has_one :wallet
has_many :orders
has_many :invoices, through: :orders
has_many :invoice_summaries
end
class Wallet
belongs_to :customer
end
class Order
has_one :invoice
belongs_to :customer
end
class Invoice
belongs_to :order
belongs_to :invoice_summary
end
class InvoiceSummary
belongs_to :customer
has_many :invoices
end
Run Code Online (Sandbox Code Playgroud)
主要问题是我想模拟我的对象的生命周期,这意味着:
实例化将用于所有测试的客户和钱包(无需重新初始化)
模拟时间流,创建和更新多个订单/发票对象和一些invoice_summaries.
对于订单/发票/ invoice_summaries的创建和更新,我想有类似的方法
def create_order_1
# code specific to create my first order, return the created order
end
def create_order_2
# code specific to create my second order, return the created order
end
.
.
. …Run Code Online (Sandbox Code Playgroud)