2015-06-05 3 views
0

См. Пример. Его не настоящий код, но покажет проблему. В генераторе кода дважды вызывается с другими аргументами. Я хочу проверить один вызов с вызовом arg, а остальные вызовыКак использовать minitest/mock для вызовов с заглушкой с ожиданием

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 
    generator.expects(:bundle_command).with('install').once 
    generator.stubs(:bundle_command).with('exec spring binstub --all') 

    generator.bundle_command("install") 
    generator.bundle_command("exec spring binstub --all") 
end 

ответ

0

значение погасил работает только в пределах блока, так что вы, вероятно, следует:

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 
Смежные вопросы