我下面有一个ChefSpec测试,我不确定它是否是ChefSpec中的错误。 但是,每当我在上下文块下模拟库函数时,该模拟库都不会模拟该函数的值并导致测试失败。奇怪的是,当所有“ it”块都停留在该上下文块内时,通过的测试(模拟起作用),但是如果我在该上下文块之外添加任何其他“ it”块,则模拟将无法模拟库函数,并且开始走进他们。
有什么办法可以解决或解决此问题?谢谢
context "when site_tool is not set (default)" do
#This mocking block is not working properly inside the context block.
#If I move everything out of this context block, everything works fine
# including the mocking library function below.
# The error is basically it tried to step into the library function,
# even though its not supposed to as I have mocked it out
# Is there a different way of mocking library function
#specifically for outside and inside context block??
before do
allow_any_instance_of(Chef::Recipe)
.to receive(:get_service_account_password)
.with(site[:app][:permissions][:base_username])
.and_return("test_password")
end
it 'adds the default app pool' do
is_expected.to add_iis_pool('DefaultAppPool').with(
...
)
end
## More complicated 'it' blocks below
end