ChefSpec - mocking library function is not working properly under context block

Hi I have a ChefSpec test below, I am not sure if it is a bug in ChefSpec or not.
However, whenever I mocked a library function under context block, the mocking library did not mock the value for the function and caused the failure of the test. The odd thing is the test passed (the mocking worked) when all the 'it' blocks stayed inside that context block, but if I add any other 'it' block outside that context block, the mocking will fail to mock the library function and start stepping into them.

Is there any way to fix or work around this? Thanks

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 
                    .to receive(:get_service_account_password)

            it 'adds the default app pool' do
            ## More complicated 'it' blocks below