我正在为以下代码编写测试:
module Clockwork
every(10.minutes, SomeBackgroundJob)
end
every
是Clockwork::Methods
模块的实例方法。
在RSpec中,我可以编写以下内容来测试模块方法是否被调用:
expect_any_instance_of(Clockwork::Methods).to(
receive(:every).with(10.minutes, SomeBackgroundJob)
)
但是我不确定如何在minitest / mocha中做到这一点。
我正在尝试以下方法:
class ClockTest < ActiveSupport::TestCase
test "it calls the job" do
module ::Clockwork; module Methods; end; end
Clockwork::Methods.any_instance.expects(:every).with(
10.minutes,
SomeBackgroundJob
)
require './clock.rb'
end
end
使用此代码我得到undefined method any_instance
。我认为这是因为Clockword::Methods
是一个模块而any_instance
仅在类上定义。什么是适当的Minitest / mocha方法?我只想检查方法是否被调用,我不希望它实际运行。