使用Minitest调用如何测试方法?

时间:2016-11-17 17:50:22

标签: ruby minitest

class Post
  def save
    Mailer.notify!('bla')
    true
  end
end

如何在调用post.save时测试Mailer.notify方法被触发?并有正确的论据。

通过RSpec,我通常会这样做:

expect(Mailer).to receive(:notify!).with('bla')
post.save

提前谢谢!

2 个答案:

答案 0 :(得分:3)

您可以这样做:

$heading = ['first name', 'last name'];

是的,这在RSpec中更容易,更直观......

答案 1 :(得分:1)

对于最小测试的嘲笑,我喜欢使用摩卡宝石https://github.com/freerange/mocha

我将是:

Mailer.expects(:notify!).with('bla').at_least_once
相关问题