-
Notifications
You must be signed in to change notification settings - Fork 132
/
strict_mode_test.exs
73 lines (59 loc) · 1.98 KB
/
strict_mode_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
defmodule ExVCR.StrictModeTest do
use ExVCR.Mock
use ExUnit.Case, async: false
@dummy_cassette_dir "tmp/vcr_tmp/vcr_cassettes_strict_mode"
@port 35007
@url "http://localhost:#{@port}/server"
@http_server_opts [path: "/server", port: @port, response: "test_response"]
setup_all do
File.rm_rf(@dummy_cassette_dir)
on_exit fn ->
File.rm_rf(@dummy_cassette_dir)
HttpServer.stop(@port)
:ok
end
HTTPotion.start
HttpServer.start(@http_server_opts)
:ok
end
setup do
ExVCR.Config.cassette_library_dir(@dummy_cassette_dir)
end
test "it makes HTTP calls if not set" do
use_cassette "strict_mode_off", strict_mode: false do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
end
test "it throws an error when set and no cassette recorded" do
use_cassette "strict_mode_on", strict_mode: true do
try do
HTTPotion.get(@url, []).body =~ ~r/test_response/
assert(false, "Shouldn't get here")
catch
"A matching cassette was not found" <> _ -> :ok
_ -> assert(false, "Encountered unexpected `throw`")
end
end
end
test "it uses a cassette if it exists" do
use_cassette "strict_mode_cassette", strict_mode: false do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
use_cassette "strict_mode_cassette", strict_mode: true do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
end
test "it does not uses a cassette when override the defaut config" do
ExVCR.Setting.set(:strict_mode, true)
use_cassette "strict_mode_cassette", strict_mode: false do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
use_cassette "strict_mode_cassette" do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
use_cassette "strict_mode_cassette", strict_mode: true do
assert HTTPotion.get(@url, []).body =~ ~r/test_response/
end
ExVCR.Setting.set(:strict_mode, false)
end
end