Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule ExVCR.StrictModeTest do | ||
use ExVCR.Mock | ||
use ExUnit.Case, async: false | ||
|
||
@dummy_cassette_dir "tmp/vcr_tmp/vcr_cassettes_strict_mode" | ||
@port 34007 | ||
@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 | ||
assert_raise ExVCR.RequestNotMatchError, fn -> | ||
HTTPotion.get(@url, []).body =~ ~r/test_response/ | ||
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 | ||
end |