-
Notifications
You must be signed in to change notification settings - Fork 132
/
ignore_localhost_test.exs
68 lines (60 loc) · 2.69 KB
/
ignore_localhost_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
defmodule ExVCR.IgnoreLocalhostTest do
use ExVCR.Mock
use ExUnit.Case, async: false
@port 35012
@url "http://localhost:#{@port}/server"
setup_all do
HTTPotion.start
on_exit fn ->
HttpServer.stop(@port)
end
:ok
end
test "it does not record localhost requests when the config has been set" do
use_cassette "ignore_localhost_on", ignore_localhost: true do
HttpServer.start(path: "/server", port: @port, response: "test_response_before")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/
HttpServer.stop(@port)
# this method call should NOT be mocked
HttpServer.start(path: "/server", port: @port, response: "test_response_after")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_after/
HttpServer.stop(@port)
end
end
test "it records localhost requests when the config has not been set" do
use_cassette "ignore_localhost_unset" do
HttpServer.start(path: "/server", port: @port, response: "test_response_before")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/
HttpServer.stop(@port)
# this method call should be mocked
HttpServer.start(path: "/server", port: @port, response: "test_response_after")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/
HttpServer.stop(@port)
end
end
test "ignore_localhost option works with request headers" do
use_cassette "ignore_localhost_with_headers", ignore_localhost: true do
non_localhost_url = "http://127.0.0.1:#{@port}/server"
HttpServer.start(path: "/server", port: @port, response: "test_response_before")
assert HTTPotion.get(non_localhost_url, headers: ["User-Agent": "ExVCR"]).body =~ ~r/test_response_before/
HttpServer.stop(@port)
# this method call should be mocked
HttpServer.start(path: "/server", port: @port, response: "test_response_after")
assert HTTPotion.get(non_localhost_url, headers: ["User-Agent": "ExVCR"]).body =~ ~r/test_response_before/
HttpServer.stop(@port)
end
end
test "it records localhost requests when overrides the config setting" do
ExVCR.Setting.set(:ignore_localhost, true)
use_cassette "ignore_localhost_unset", ignore_localhost: false do
HttpServer.start(path: "/server", port: @port, response: "test_response_before")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/
HttpServer.stop(@port)
# this method call should be mocked
HttpServer.start(path: "/server", port: @port, response: "test_response_after")
assert HTTPotion.get(@url, []).body =~ ~r/test_response_before/
HttpServer.stop(@port)
end
ExVCR.Setting.set(:strict_mode, false)
end
end