我正在阅读关于spies的内容,我看不出它之间存在差异:
File "/usr/lib/python2.7/dist-packages/django/forms/models.py", line 294, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (is_admin) specified for Freelancer
而且:
RSpec.describe "have_received" do
it "passes when the message has been received" do
invitation = spy('invitation', deliver: "ok")
invitation.deliver
expect(invitation).to have_received(:deliver)
end
end
两个例子都没有问题。我使用RSpec.describe "have_received" do
it "passes when the message has been received" do
invitation = double('invitation', deliver: "ok")
invitation.deliver
expect(invitation).to have_received(:deliver)
end
end
答案 0 :(得分:0)
正如@max在评论中所说,区别在于我可以使用spy
而不说deliver: "ok"
。所以,运行这个:
RSpec.describe "have_received" do
it "passes when the message has been received" do
invitation = spy('invitation')
invitation.deliver
expect(invitation).to have_received(:deliver)
end
end
RSpec.describe "have_received" do
it "passes when the message has been received" do
invitation = double('invitation')
invitation.deliver
expect(invitation).to have_received(:deliver)
end
end
第一个例子将通过,但不是第二个。
现在我明白了这意味着......
“你可以使用任何测试双重(或部分双重)作为间谍,但必须设置双重监视你关心的消息。间谍自动监视所有消息,或者你可以允许消息窥探它。“