It turns out that this is possible without any trickery.
According to this Google Groups thread:
You can use
VCR.http_stubbing_adapter.http_connections_allowed?
However (as the author explained) this method isn't publicly documented, and (as the author accurately predicted) is not available in the 2.x codeline. However, this did cause me to review the VCR source directly out of a mixture of curiosity and desperation. I found the following in lib/vcr.rb:294:
def real_http_connections_allowed?
return current_cassette.recording? if current_cassette
!!(configuration.allow_http_connections_when_no_cassette? || @turned_off)
end
Since current_cassette.recording?
is publicly accessible, it does exactly what I need without any hacking:
expect(subject).to receive(:sleep) if !VCR.current_cassette.recording?