Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there record mode to delete the current cassette and write new cassette? #628

Closed
FayeFang opened this issue Dec 9, 2016 · 11 comments
Closed

Comments

@FayeFang
Copy link

FayeFang commented Dec 9, 2016

There are four record mode: :all, :new_episodes, :none, :once. They all keep the old cassette.

I am using :all currently, but it keeps lots of unused and old requests on file. So what I want to do is to create a new record mode to delete current cassette and write a new one.

Any experience with this? Thanks!

@ecnalyr
Copy link
Collaborator

ecnalyr commented Dec 12, 2016

I am fairly confident there is not a method to delete unused cassettes.

One big reason may be because we don't have a way of knowing if a recorded request is truly unused.

Please see this issue that contains a similar request/suggestion and the details I wrote in the first comment (especially the second part of the comment).

@FayeFang
Copy link
Author

FayeFang commented Dec 12, 2016

Lol @ecnalyr the person who posted that issue is a co-worker of mine. Apparently it has been a persistent issue for us!

I actually have a small hack to make what I want to happen. In the code below, whenever the user wants to re-record any particular cassette, the current one will be deleted first. This way, the user is not deleting all cassettes, but the only relevant cassette the user wants to re-record.

And I don't see it being any dangerous. What do you think?

And we can certainly re-write this small hack into a real new feature.

module CassetteCleaner
  def insert_cassette(name, options = {})
    if configuration.default_cassette_options[:record] == :all
      current_cassette = VCR::Cassette.new(name, options).file
      File.delete(current_cassette) if File.exist?(current_cassette)
    end

    super
  end
end
VCR.extend(CassetteCleaner)

@ecnalyr
Copy link
Collaborator

ecnalyr commented Dec 12, 2016

I think it would be reasonable to put it up for review if it required both

  • a flag to be enabled
    and
  • is clearly documented that it is destructive to any previously recorded requests.

I have to make it clear that I have the breadth of knowledge of VCR that other contributors/maintainers have and there's a chance there's a good reason why something like this doesn't already exist.

But I like the idea of having a clean PR up for review.

@FayeFang
Copy link
Author

FayeFang commented Dec 12, 2016

Thanks for your response! And sure I can put up a pr for review.

@mcfiredrill
Copy link
Collaborator

@krainboltgreene
Copy link
Contributor

krainboltgreene commented Dec 8, 2017 via email

@ryanseys
Copy link
Contributor

@ecnalyr

What about if this was implemented as a new overwrite record mode? It would behave exactly like the all record mode, except it would delete the current cassette file if it exists beforehand?

I'm happy to try to throw together a PR if this sounds reasonable?

@ryanseys
Copy link
Contributor

I also see there is this PR that needs to be back-merged? #769

If I work on rebasing that, would it be a reasonable way to solve this problem?

@ryanseys
Copy link
Contributor

I rebased into a new PR an option that should allow this functionality out of the box: #946

Please take a look!

@ryanseys
Copy link
Contributor

ryanseys commented Oct 19, 2022

#946 is now merged. Not yet released, but we can mark this as fixed.

@olleolleolle
Copy link
Member

Fixed in #946.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants