minitest - 期望从模块扩展时调用方法

时间:2017-11-06 22:19:21

标签: ruby-on-rails ruby mocha minitest

我正在为以下代码编写测试:

module Clockwork
  every(10.minutes, SomeBackgroundJob)
end

everyClockwork::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方法?我只想检查方法是否被调用,我不希望它实际运行。

0 个答案:

没有答案
相关问题