If I was using RSpec I could test if a method is being called like so:
expect(obj).to receive(:method)
What is the equivalent in MiniTest?
For this purpose Minitest has a .expect :call
which allows you to check if method is getting called:
describe Post do
before do
@post = FactoryGirl.build(:post)
end
describe "when saving" do
it "calls the create_slug method before validation" do
mock_method = MiniTest::Mock.new
mock_method.expect :call, "return_value", []
@post.stub :create_slug, mock_method do
@post.save
end
mock_method.verify
end
end
end
If @post.create_slug was called, test will pass. Otherwise test will raise a MockExpectationError.
Unfortunately this feature is not documented very well. I found this answer from here: https://github.com/seattlerb/minitest/issues/216