尝试测试是否调用方法时出现MockExcpetionError

时间:2018-06-24 21:41:31

标签: ruby mocking minitest stubbing

我正在尝试测试以下代码块,以确保当我调用start_game时,它会调用make_rand_num方法。

  def make_rand_num
    @prng1 = Random.new(@seed)
  end

  def start_game
    make_rand_num
  end

这是我编写的测试,试图确保在调用start_game时调用make_rand_num。

  def test_game_start
    double = Minitest::Mock.new('double')
    double.expect :make_rand_num, Random
    @game.start_game
    assert_mock double
  end

我不确定我是否缺少模拟/存根的知识,因为我是测试和Ruby的新手,但我一直收到此错误:

MockExpectationError: expected make_rand_num() => Random

make_rand_num不会返回随机类型的对象,还是我完全想不到其他点吗?

0 个答案:

没有答案
相关问题