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

Add localhost_ignored? to request_ignorer #895

Merged
merged 2 commits into from
Jul 7, 2021
Merged

Add localhost_ignored? to request_ignorer #895

merged 2 commits into from
Jul 7, 2021

Conversation

ThHareau
Copy link
Contributor

@ThHareau ThHareau commented Jul 1, 2021

In our setup, we want to use VCR in a helper, which needs to ignore localhost. At the end of the helper, we want to unignore localhost, but only if VCR was not configured to ignore localhost before.

module SomeHelper
    def action
        with_vcr do 
            call
        end
    end

    private

    def with_vcr(&block)
        localhost_already_ignored = VCR.request_ignorer.localhost_ignored?
        VCR.request_ignorer.ignore_localhost = true unless localhost_already_ignored

        VCR.use_cassette("helper_cassette") { yield block }
        VCR.request_ignorer.ignore_localhost = false unless localhost_already_ignored
    end
end

This PR adds the method localhost_ignored?.

olleolleolle
olleolleolle previously approved these changes Jul 7, 2021
Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a helpful addition to this object. It wraps access to the set of ignored hosts and the constant, in a useful name. Thanks for adding this.

@ThHareau
Copy link
Contributor Author

ThHareau commented Jul 7, 2021

You are welcome :)

Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@olleolleolle olleolleolle merged commit 6d7b577 into vcr:master Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants