我正在尝试实现并学习测试(似乎minitest是正确的选择)。但是,我惨败于测试一个内部模块类方法。
这里是我试图做的用例。(也许我完全走了错误的路)
module Zombie
class << self
# This is the method/code I want to test/execute
def intimidate
roar('slardar')
end
# This is the method that is internal, that I want to stub.
# Actual method(not this mocked one) is stateful. So I want to have
# mocked predefined data.
def roar(a)
'rawrger' + a
end
end
end
# Test Thingy
class ZombieTest < Minitest::Test
def test_mr_mock
@mock = Minitest::Mock.new
@mock.expect(:roar, 'rawrgerslardar', ['slardar'])
Zombie.stub :roar, @mock do
Zombie.intimidate
end
@mock.verify
end
end