Last active
January 6, 2024 15:13
-
-
Save dideler/062a6d6722e137db55b2 to your computer and use it in GitHub Desktop.
Show unused VCR cassettes. Use with vcr gem: https://github.com/vcr/vcr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Require this file in spec_helper.rb to show which cassettes are not being used | |
# after the test suite has run. Then you can decide if you want to delete them. | |
require 'vcr' | |
require 'set' | |
USED_CASSETTES = Set.new | |
module CassetteReporter | |
def insert_cassette(name, options = {}) | |
USED_CASSETTES << VCR::Cassette.new(name, options).file | |
super | |
end | |
end | |
VCR.extend(CassetteReporter) | |
RSpec.configure do |config| | |
config.after(:suite) do | |
cassettes = Dir['vcr_cassettes/*.yml'].map { |d| File.expand_path(d) } - USED_CASSETTES.to_a | |
if cassettes.any? | |
puts "\nUnused cassettes:" | |
puts cassettes.map { |f| File.basename(f) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is helpful, thanks!
I have refined it so that:
.yml
files in sub directories can are grabbed if like me you like to configure VCR to separate things in directories