我有這個測驗:
it "saves the notification id in the referral for future reference" do
expect { subject.perform(*args) }
.to change(referral, :notification_id).from(nil).to(customer_notification_delivery.id)
end
它運行在上面的代碼是:
if notification.present?
referral.update(friend_customer_notification_delivery_id: notification.id)
end
我添加了一些除錯訊息,在啟動測驗后檢查它們,以確保滿足這個條件,并且代碼正在運行,我得到true了兩者
p notification.present?
p referral.update(friend_customer_notification_delivery_id: customer_notification_delivery.id)
我缺少什么嗎?為什么更新回傳 true,但值沒有在測驗中更新?
我得到的輸出:
expected #notification_id to have changed from nil to 5, but did not change
uj5u.com熱心網友回復:
referral在您的測驗中和referral在您的被測物件中是兩個不同的物件,我敢打賭。對一個的更改不會影響另一個。referral在測驗中不會神奇地從其他一些代碼所做的相關資料庫記錄中提取更新。
我通常這樣做
it "saves the notification id in the referral for future reference" do
expect { subject.perform(*args) }
.to change{ referral.reload.notification_id }.from(nil).to(customer_notification_delivery.id)
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/370150.html
