you might want to put a comment here that you're providing a hook for rspec to stub to avoid twiddling global state in the tests.  it initially doesn't make a lot of sense reading the code in isolation from the tests.