【发布时间】:2017-02-14 19:37:27
【问题描述】:
我正在尝试实施和学习测试(似乎 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
【问题讨论】: