Created
August 31, 2021 20:44
-
-
Save mmirus/acfb378356ede49da38bc53c75883323 to your computer and use it in GitHub Desktop.
Find and delete unused VCR cassettes
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
# | |
# Find and delete unused cassettes | |
# Save in spec/support/ | |
# | |
# Modified from examples found at https://github.com/vcr/vcr/issues/283 | |
# | |
module UsedCassetteReporter | |
USED_CASSETTES = Set.new | |
def insert_cassette(name, options = {}) | |
USED_CASSETTES << VCR::Cassette.new(name, options).file | |
super | |
end | |
end | |
RSpec.configure do |config| | |
config.after(:suite) do | |
all_cassettes = Dir[File.join(VCR::Cassette::Persisters::FileSystem.storage_location, '**', '*.yml')].map do |d| | |
File.expand_path(d) | |
end | |
unused_cassettes = all_cassettes - UsedCassetteReporter::USED_CASSETTES.to_a | |
unless unused_cassettes.empty? | |
puts "\nUnused cassettes to delete:" | |
puts unused_cassettes | |
unused_cassettes.each { |v| File.delete(v) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This seems like it delete cassettes that are actually being used...