class Post
def save
Mailer.notify!('bla')
true
end
end
如何在调用post.save
时测试Mailer.notify
方法被触发?并有正确的论据。
通过RSpec,我通常会这样做:
expect(Mailer).to receive(:notify!).with('bla')
post.save
提前谢谢!
答案 0 :(得分:3)
您可以这样做:
$heading = ['first name', 'last name'];
是的,这在RSpec中更容易,更直观......
答案 1 :(得分:1)
对于最小测试的嘲笑,我喜欢使用摩卡宝石https://github.com/freerange/mocha
我将是:
Mailer.expects(:notify!).with('bla').at_least_once