ruby - How to test a method is called with Minitest? -
class post def save mailer.notify!('bla') true end end
how test when post.save
called, mailer.notify
method fired? , right arguments.
with rspec do:
expect(mailer).to receive(:notify!).with('bla') post.save
thank in advance!
you can this:
describe 'post#save' "calls mailer::notify!" mock = minitest::mock.new mock.expect(:call, nil, ['bla']) mailer.stub(:notify!, mock) post.save end mock.verify end end
and yes, easier , more intuitive in rspec...
Comments
Post a Comment