我在Rspec中编写了以下测试:
expect {
...
}.to change( User.where(:profile.exists => true), :count ).by(1)
,但是这个作用域只执行一次,并且总是相同大小的相同数组。如何使rspec在预期运行代码之前和之后执行此范围?
OPs解决方案,作为答案发布
对于其他遇到类似问题的人可能有效,也可能无效。原始问题中没有语料库,也没有独立验证。
expect {
# test goes here
}.to change{ User.where(:profile.exists => true).count }.by(1)