我正在测试一些涉及电子邮件的方法,并尝试使用模拟邮件对象。我显然走错了路,因为测试第一次有效,但随后同样的测试失败了。如果有人能解释这里发生了什么,我将不胜感激。谢谢。
describe SentMessage do
before(:each) do
Notifier ||= mock('Notifier', :send_generic => true)
end
it "Sends an email" do
Notifier.should_receive(:send_generic).with(['a@contact.com'], 'test')
Notifier.send_generic(['a@contact.com'], 'test').should_not be_nil
end
it "Sends an email" do
Notifier.should_receive(:send_generic).with(['a@contact.com'], 'test')
Notifier.send_generic(['a@contact.com'], 'test').should_not be_nil
end
end
结果:
Failures:
1) SentMessage Sends an email
Failure/Error: Notifier.send_generic(['a@contact.com'], 'test').should_not be_nil
expected: not nil
got: nil
# ./spec/models/test.rb:14:in `block (2 levels) in <top (required)>'