[#54518668] General refactorings on lock spec

Using the rspec `yield_control` to test blocks instead
of assigning variables in and out.