【发布时间】:2014-03-20 11:24:08
【问题描述】:
我不明白为什么在运行我的测试时以下代码在 rspec 中不起作用。
Lead.update_status(2,2,true)
expect(Lead).to receive(:update_status).with(2, 2, true)
我也试过
Lead.update_status(2,2,true)
expect_any_instance_of(Lead).to receive(:update_status).with(2, 2, true)
我得到的错误是
(<Lead(id: integer, contact_id: integer, course_presentation_id: integer, status: integer, created_by_user_id: integer, updated_by_user_id: integer, created_at: datetime, updated_at: datetime, mailchimp_status: integer) (class)>).update_status(2, 2, true)
expected: 1 time with arguments: (2, 2, true)
received: 0 times with arguments: (2, 2, true)
请注意,如果我将 puts "test" 添加到我的代码中,则会打印出来,所以我知道 update_status 确实有效。
有什么想法吗?谢谢。
【问题讨论】:
标签: ruby-on-rails ruby rspec ruby-on-rails-4