-
Notifications
You must be signed in to change notification settings - Fork 133
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
Allow cache to be skipped when running a cassette #100
base: master
Are you sure you want to change the base?
Conversation
Adds a `skip_cache` option which can be passed to `use_cassette`, which will prevent cache from being for requests within the cassette, but will still record the responses for each. If the option is removed after recording, subsequent runs will use the correct responses.
Thanks for the PR! I think it works as long it's optional setting, but I have a question. When I try to delete $ exvcr git:(add-skip-cache-option) mix test
..
1) test uses the correct responses when recorded with skip_cache enabled (ExVCR.SkipCacheTest)
test/skip_cache_test.exs:32
Assertion with != failed, both sides are exactly equal
code: first_body != second_body
left: "6740\n"
stacktrace:
test/skip_cache_test.exs:35: (test) Also, I'm wondering if the response from diff --git a/test/skip_cache_test.exs b/test/skip_cache_test.exs
index 96ee042..daf4af5 100644
--- a/test/skip_cache_test.exs
+++ b/test/skip_cache_test.exs
@@ -5,6 +5,23 @@ defmodule ExVCR.SkipCacheTest do
alias ExVCR.Mock
alias ExVCR.Actor.Responses
+ @port 34007
+ @url 'http://localhost:#{@port}/server'
+
+ setup do
+ HttpServer.start(path: "/server", port: @port,
+ response: fn(_) ->
+ {200, [], to_string(:rand.uniform(10000))}
+ end
+ )
+
+ on_exit fn ->
+ HttpServer.stop(@port)
+ end
+
+ :ok
+ end
+
test "skips cache when the skip_cache option is passed" do
recorder = Recorder.start([skip_cache: true, fixture: "stubbed_request", adapter: ExVCR.Adapter.Httpc])
Mock.mock_methods(recorder, ExVCR.Adapter.Httpc)
@@ -37,9 +54,8 @@ defmodule ExVCR.SkipCacheTest do
end
defp make_random_requests do
- random_url = 'https://www.random.org/integers/?num=1&min=1&max=10000&col=1&base=10&format=plain&rnd=new'
- {:ok, {_res, _headers, first_body}} = :httpc.request(random_url)
- {:ok, {_res, _headers, second_body}} = :httpc.request(random_url)
+ {:ok, {_res, _headers, first_body}} = :httpc.request(@url)
+ {:ok, {_res, _headers, second_body}} = :httpc.request(@url)
[first_body, second_body]
end
(END) |
The You're right, it's not all that clear in the test. Any suggestions on how to make it more readable? Comments may do... MUCH prefer using a local webserver, will update today to use that. |
Thanks for explanation.
I don't have good answer, but if it's intended to manually customized cassette (rather than automatically recorded), one option might be to put under |
There shouldn't be a need to manually customise the JSON itself, it's more like there's a manual step involved in actually recording it. Will have a think about this, haven't had time to update this PR yet. |
Adds a
skip_cache
option which can be passed touse_cassette
, which will prevent cache from being for requests within the cassette, but will still record the responses for each. If the option is removed after recording, subsequent runs will use the correct responses.We need this for cassettes which include more than one request to the same URL, which would be matched against the cache during the first recording, but should return different responses.
This fixes a problem we're having using the library, but appreciate it might not be the preferred fix. If you've got any suggestions on how to do this better, happy to hear them.