1
假设我们有一个具有从另一个 存根依赖对象
class Ship
def initialize
...
end
def launch
ShipLauncher.new(self, platform: platform)
end
end
class ShipLauncher
def initialize(ship, platform:)
...
end
end
垂直依赖的对象,我们要对它进行测试:
it do
allow(ShipLauncher).to receive(:new)
ship = Ship.new
ship.launch
expect(ShipLauncher).to have_received(:new).with(ship, platform: 'x')
end
到现在为止一切似乎都不错,但如果我们改变了ShipLauncher类这样
class ShipLauncher
def initialize(ship, platform_number:)
...
end
end
测试将通过WH它不应该因为ShipLauncher类需要另一个参数。我做错了什么?我必须用集成测试来测试它吗?如果ShipLauncher类隐藏了很大的复杂性,会发生什么?我必须将所有的依赖关系存根?