gpt4 book ai didi

ruby-on-rails - rails : problem setting expectations on mock model in RSpec

转载 作者:行者123 更新时间:2023-12-04 03:35:55 24 4
gpt4 key购买 nike

我正在尝试对模拟的 ActiveRecord 模型设置期望。我创建了以下示例,它应该根据我可以找到的文档通过。

it "should pass given the correct expectations" do
payment = mock_model(Payment)
payment.should_receive(:membership_id).with(12)
payment.membership_id = 12
end

它因错误“...Mock 'Payment_1004'收到意外消息:membership_id= with (12)”而失败

我意识到我正在测试模拟框架,我只是想了解如何设置期望。

最佳答案

您对错误的方法名称设置了期望 - :membership_id是“ setter/getter ”,:membership_id=是“二传手”。正确的行是:

payment.should_receive(:membership_id=).with(12)

关于ruby-on-rails - rails : problem setting expectations on mock model in RSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1127021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com