Ruby on rails 如何将minitest/mock用于带有expect的存根调用
参见示例。这不是真正的代码,但显示了问题所在。 在代码生成器中使用其他参数调用两次。我想检查arg install的一个调用是否被调用,以及存根其他调用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
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