Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将minitest/mock用于带有expect的存根调用_Ruby On Rails_Mocking_Minitest - Fatal编程技术网

Ruby on rails 如何将minitest/mock用于带有expect的存根调用

Ruby on rails 如何将minitest/mock用于带有expect的存根调用,ruby-on-rails,mocking,minitest,Ruby On Rails,Mocking,Minitest,参见示例。这不是真正的代码,但显示了问题所在。 在代码生成器中使用其他参数调用两次。我想检查arg install的一个调用是否被调用,以及存根其他调用 def test bundle_command_mock = Minitest::Mock.new bundle_command_mock.expect(:call, nil, ['install']) generator.stub(:bundle_command, bundle_command_mock) do |g| g

参见示例。这不是真正的代码,但显示了问题所在。 在代码生成器中使用其他参数调用两次。我想检查arg install的一个调用是否被调用,以及存根其他调用

def test
  bundle_command_mock = Minitest::Mock.new
  bundle_command_mock.expect(:call, nil, ['install'])
  generator.stub(:bundle_command, bundle_command_mock) do |g|
    g.bundle_command('install')
    g.bundle_command('exec spring binstub --all') # <-- This call raise error No more expects available for :call: ["exec spring binstub --all"]
  end

  bundle_command_mock.verify
end
def test
  bundle_command_mock = Minitest::Mock.new
  bundle_command_mock.expect(:call, nil, ['install'])
  generator.stub(:bundle_command, bundle_command_mock) do |g|
    g.bundle_command('install')
    g.bundle_command('exec spring binstub --all') # <-- This call raise error No more expects available for :call: ["exec spring binstub --all"]
  end

  bundle_command_mock.verify
end

存根值仅在块内工作,因此您可能应该:

def测试
bundle\u命令\u mock=Minitest::mock.new
bundle_command_mock.expect(:call,nil,['install'])
生成器.stub(:bundle_命令,bundle_命令_mock)do|g|
g、 bundle_命令('install')
g、 bundle_命令('exec-spring-binstub--all')#
def test
  bundle_command_mock = Minitest::Mock.new
  bundle_command_mock.expect(:call, nil, ['install'])
  generator.stub(:bundle_command, bundle_command_mock) do |g|
    g.bundle_command('install')
    g.bundle_command('exec spring binstub --all') # <-- This call raise error No more expects available for :call: ["exec spring binstub --all"]
  end

  bundle_command_mock.verify
end