Skip to content

Commit

Permalink
Updates for elixir v0.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
parroty committed Mar 10, 2014
1 parent 5c23b93 commit cb3124c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/exvcr/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule ExVCR.Filter do

defp replace(body, []), do: body
defp replace(body, [{pattern, placeholder}|tail]) do
replace(String.replace(body, %r/#{pattern}/, placeholder), tail)
replace(String.replace(body, ~r/#{pattern}/, placeholder), tail)
end

@doc """
Expand All @@ -30,6 +30,6 @@ defmodule ExVCR.Filter do
Remove query params from the specified url.
"""
def strip_query_params(url) do
url |> String.replace(%r/\?.+$/, "")
url |> String.replace(~r/\?.+$/, "")
end
end
2 changes: 1 addition & 1 deletion lib/exvcr/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ defmodule ExVCR.Mock do
Normalize fixture name for using as json file names, which removes whitespaces and align case.
"""
def normalize_fixture(fixture) do
fixture |> String.replace(%r/\s/, "_") |> String.downcase
fixture |> String.replace(~r/\s/, "_") |> String.downcase
end
end
2 changes: 1 addition & 1 deletion lib/exvcr/task/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ExVCR.Task.Runner do
@check_header_format " %-40s %-20s %-20s\n"
@check_content_format " %-40s %-20d %-20d\n"
@date_format "%04d/%02d/%02d %02d:%02d:%02d"
@json_file_pattern %r/\.json$/
@json_file_pattern ~r/\.json$/

@doc """
Use specified path to show the list of vcr cassettes.
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Vcr do
aliases: [d: :dir, i: :interactive, a: :all])

pattern = cond do
options[:all] -> %r/.*/
options[:all] -> ~r/.*/
Enum.count(files) == 1 -> Enum.at(files, 0)
true -> nil
end
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[ "cowboy": {:git, "git://github.com/extend/cowboy.git", "6672ea04155a075e60381413bf9b65b3974b7d57", [tag: "0.9.0"]},
"cowlib": {:git, "git://github.com/extend/cowlib.git", "34a39ef28ca841fb9233ce9df3ec654eb321c5e5", [ref: "0.3.0"]},
"exactor": {:git, "git://github.com/sasa1977/exactor.git", "f7f6bae7fead5e0e5525581d44311f803169fa4e", []},
"excoveralls": {:git, "git://github.com/parroty/excoveralls.git", "33fad212e96c9f3f0a768b9bc3b31a7901261f07", []},
"excoveralls": {:git, "git://github.com/parroty/excoveralls.git", "407cf15d4085cbe3b628cd16193270b44560f607", []},
"exprintf": {:git, "git://github.com/parroty/exprintf.git", "586c8e07c65805cf8e53d5855bbb7fd1472b777a", []},
"hackney": {:git, "git://github.com/benoitc/hackney.git", "7f2a0b5996313d930277786e7ff5d538e9346547", [tag: "0.10.1"]},
"hackney_lib": {:git, "https://github.com/benoitc/hackney_lib.git", "eecdb481f1d38bfb194896bffdf9bdcdd967ae96", [tag: "0.2.2"]},
"http_server": {:git, "git://github.com/parroty/http_server.git", "d694486e290c6742a68c09aa190977a4f387e8d1", []},
"httpoison": {:git, "git://github.com/edgurgel/httpoison.git", "218528a464361693732aafa473e205405e2aa314", []},
"httpotion": {:git, "git://github.com/myfreeweb/httpotion.git", "1e2c234b025c41cb2ff7570a35efa9f12d28f31b", []},
"ibrowse": {:git, "git://github.com/cmullaparthi/ibrowse.git", "866b0ff5aca229f1ef53653eabc8ed1720c13cd6", [ref: "866b0ff5aca229f1ef53653eabc8ed1720c13cd6"]},
"jsex": {:git, "git://github.com/talentdeficit/jsex.git", "3db1d520e00fb28c3eee4e5b30645d5878037c38", []},
"jsex": {:git, "git://github.com/talentdeficit/jsex.git", "65aa6ae7c1543a0c4e83032c04626af7be7a7f3e", []},
"jsx": {:git, "git://github.com/talentdeficit/jsx.git", "e50af6e109cb03bd26acf715cbc77de746507d1d", [tag: "v1.4.3"]},
"meck": {:git, "git://github.com/eproxus/meck.git", "1286aba1cb6bbd6c9fc3f817740758b224843ee7", []},
"mimetypes": {:git, "git://github.com/spawngrid/mimetypes.git", "47d37a977a7d633199822bf6b08353007483d00f", [ref: "master"]},
Expand Down
4 changes: 2 additions & 2 deletions test/adapter_hackney_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defmodule ExVCR.Adapter.HackneyTest do
use_cassette "hackney_get" do
{:ok, _status_code, _headers, client} = :hackney.request(:get, "http://www.example.com", [], [], [])
{:ok, body} = :hackney.body(client)
assert body =~ %r/Example Domain/
assert body =~ ~r/Example Domain/
end
end

Expand All @@ -32,7 +32,7 @@ defmodule ExVCR.Adapter.HackneyTest do

test "get request" do
use_cassette "httpoison_get" do
assert HTTPoison.get("http://example.com").body =~ %r/Example Domain/
assert HTTPoison.get("http://example.com").body =~ ~r/Example Domain/
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/adapter_httpc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ defmodule ExVCR.Adapter.HttpcTest do
test "example httpc request/1" do
use_cassette "example_httpc_request_1" do
{:ok, {{_http_version, _status_code = 200, _reason_phrase}, _headers, body}} = :httpc.request('http://example.com')
assert to_string(body) =~ %r/Example Domain/
assert to_string(body) =~ ~r/Example Domain/
end
end

test "example httpc request/4" do
use_cassette "example_httpc_request_4" do
{:ok, {{_, 200, _reason_phrase}, _headers, body}} = :httpc.request(:get, {'http://example.com', ''}, '', '')
assert to_string(body) =~ %r/Example Domain/
assert to_string(body) =~ ~r/Example Domain/
end
end

Expand Down
16 changes: 8 additions & 8 deletions test/adapter_ibrowse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule ExVCR.Adapter.IBrowseTest do
:ibrowse.start
{:ok, status_code, _headers, body} = :ibrowse.send_req('http://example.com', [], :get)
assert status_code == '200'
assert to_string(body) =~ %r/Example Domain/
assert to_string(body) =~ ~r/Example Domain/
end
end

Expand All @@ -21,11 +21,11 @@ defmodule ExVCR.Adapter.IBrowseTest do
:ibrowse.start
{:ok, status_code, _headers, body} = :ibrowse.send_req('http://example.com', [], :get)
assert status_code == '200'
assert to_string(body) =~ %r/Example Domain/
assert to_string(body) =~ ~r/Example Domain/

{:ok, status_code, _headers, body} = :ibrowse.send_req('http://example.com/2', [], :get)
assert status_code == '404'
assert to_string(body) =~ %r/Example Domain/
assert to_string(body) =~ ~r/Example Domain/
end
end

Expand All @@ -40,7 +40,7 @@ defmodule ExVCR.Adapter.IBrowseTest do
test "httpotion" do
use_cassette "example_httpotion" do
HTTPotion.start
assert HTTPotion.get("http://example.com", []).body =~ %r/Example Domain/
assert HTTPotion.get("http://example.com", []).body =~ ~r/Example Domain/
end
end

Expand Down Expand Up @@ -78,13 +78,13 @@ defmodule ExVCR.Adapter.IBrowseTest do

test "custom with valid response" do
use_cassette "response_mocking", custom: true do
assert HTTPotion.get("http://example.com", []).body =~ %r/Custom Response/
assert HTTPotion.get("http://example.com", []).body =~ ~r/Custom Response/
end
end

test "custom response with regexp url" do
use_cassette "response_mocking_regex", custom: true do
HTTPotion.get("http://example.com/something/abc", []).body =~ %r/Custom Response/
HTTPotion.get("http://example.com/something/abc", []).body =~ ~r/Custom Response/
end
end

Expand All @@ -106,14 +106,14 @@ defmodule ExVCR.Adapter.IBrowseTest do

test "match method succeeds" do
use_cassette "method_mocking", custom: true do
HTTPotion.post("http://example.com", "").body =~ %r/Custom Response/
HTTPotion.post("http://example.com", "").body =~ ~r/Custom Response/
end
end

test "match method fails" do
assert_raise ExVCR.InvalidRequestError, fn ->
use_cassette "method_mocking", custom: true do
HTTPotion.put("http://example.com", "").body =~ %r/Custom Response/
HTTPotion.put("http://example.com", "").body =~ ~r/Custom Response/
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/mix/tasks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Mix.Tasks.VcrTest do
test "mix vcr" do
assert capture_io(fn ->
Mix.Tasks.Vcr.run([])
end) =~ %r/Showing list of cassettes/
end) =~ ~r/Showing list of cassettes/
end

test "mix vcr -h" do
Expand All @@ -37,15 +37,15 @@ defmodule Mix.Tasks.VcrTest do
File.touch!(@dummy_path <> @dummy_file)
assert capture_io(fn ->
Mix.Tasks.Vcr.Delete.run(["--dir", @dummy_path, @dummy_file])
end) =~ %r/Deleted dummy.json./
end) =~ ~r/Deleted dummy.json./
assert(File.exists?(@dummy_path <> @dummy_file) == false)
end

test "mix vcr.delete with --interactive option" do
File.touch!(@dummy_path <> @dummy_file)
assert capture_io("y\n", fn ->
Mix.Tasks.Vcr.Delete.run(["-i", "--dir", @dummy_path, @dummy_file])
end) =~ %r/delete dummy.json?/
end) =~ ~r/delete dummy.json?/
assert(File.exists?(@dummy_path <> @dummy_file) == false)
end

Expand All @@ -55,7 +55,7 @@ defmodule Mix.Tasks.VcrTest do

assert capture_io("y\n", fn ->
Mix.Tasks.Vcr.Delete.run(["-a", "--dir", @dummy_path, @dummy_file])
end) =~ %r/Deleted dummy.json./
end) =~ ~r/Deleted dummy.json./

assert(File.exists?(@dummy_path <> @dummy_file) == false)
assert(File.exists?(@dummy_path <> @dummy_file2) == false)
Expand All @@ -64,6 +64,6 @@ defmodule Mix.Tasks.VcrTest do
test "mix vcr.delete with invalid file" do
assert capture_io(fn ->
Mix.Tasks.Vcr.Delete.run(["--dir", @dummy_path])
end) =~ %r/invalid parameter is specified/
end) =~ ~r/invalid parameter is specified/
end
end
10 changes: 5 additions & 5 deletions test/recorder_hackney_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ defmodule ExVCR.RecorderHackneyTest do

test "forcefully getting response from server by removing json in advance" do
use_cassette "server1" do
assert HTTPoison.get("http://localhost:35000/server", []).body =~ %r/test_response/
assert HTTPoison.get("http://localhost:35000/server", []).body =~ ~r/test_response/
end
end

test "forcefully getting response from server, then loading from cache by recording twice" do
use_cassette "server2" do
assert HTTPoison.get("http://localhost:35000/server", []).body =~ %r/test_response/
assert HTTPoison.get("http://localhost:35000/server", []).body =~ ~r/test_response/
end
use_cassette "server2" do
assert HTTPoison.get("http://localhost:35000/server", []).body =~ %r/test_response/
assert HTTPoison.get("http://localhost:35000/server", []).body =~ ~r/test_response/
end
end

Expand All @@ -37,15 +37,15 @@ defmodule ExVCR.RecorderHackneyTest do
test "replace sensitive data" do
ExVCR.Config.filter_sensitive_data("test_response", "PLACEHOLDER")
use_cassette "sensitive_data" do
assert HTTPoison.get("http://localhost:35000/server", []).body =~ %r/PLACEHOLDER/
assert HTTPoison.get("http://localhost:35000/server", []).body =~ ~r/PLACEHOLDER/
end
ExVCR.Config.filter_sensitive_data(nil)
end

test "filter url param flag removes url params when recording cassettes" do
ExVCR.Config.filter_url_params(true)
use_cassette "example_ignore_url_params" do
assert HTTPoison.get("http://localhost:35000/server?should_not_be_contained", []).body =~ %r/test_response/
assert HTTPoison.get("http://localhost:35000/server?should_not_be_contained", []).body =~ ~r/test_response/
end
json = File.read!("#{__DIR__}/../#{@dummy_cassette_dir}/example_ignore_url_params.json")
refute String.contains?(json, "should_not_be_contained")
Expand Down
10 changes: 5 additions & 5 deletions test/recorder_httpc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ defmodule ExVCR.RecorderHttpcTest do
test "forcefully getting response from server by removing json in advance" do
use_cassette "server1" do
{:ok, {_, _, body}} = :httpc.request('http://localhost:36000/server')
assert body =~ %r/test_response/
assert body =~ ~r/test_response/
end
end

test "forcefully getting response from server, then loading from cache by recording twice" do
use_cassette "server2" do
{:ok, {_, _, body}} = :httpc.request('http://localhost:36000/server')
assert body =~ %r/test_response/
assert body =~ ~r/test_response/
end

use_cassette "server2" do
{:ok, {_, _, body}} = :httpc.request('http://localhost:36000/server')
assert body =~ %r/test_response/
assert body =~ ~r/test_response/
end
end

test "replace sensitive data" do
ExVCR.Config.filter_sensitive_data("test_response", "PLACEHOLDER")
use_cassette "server_sensitive_data" do
{:ok, {_, _, body}} = :httpc.request('http://localhost:36000/server')
assert body =~ %r/PLACEHOLDER/
assert body =~ ~r/PLACEHOLDER/
end
ExVCR.Config.filter_sensitive_data(nil)
end
Expand All @@ -43,7 +43,7 @@ defmodule ExVCR.RecorderHttpcTest do
ExVCR.Config.filter_url_params(true)
use_cassette "example_ignore_url_params" do
{:ok, {_, _, body}} = :httpc.request('http://localhost:36000/server?should_not_be_contained')
assert body =~ %r/test_response/
assert body =~ ~r/test_response/
end
json = File.read!("#{__DIR__}/../#{@dummy_cassette_dir}/example_ignore_url_params.json")
refute String.contains?(json, "should_not_be_contained")
Expand Down
10 changes: 5 additions & 5 deletions test/recorder_ibrowse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ defmodule ExVCR.RecorderIBrowseTest do

test "forcefully getting response from server by removing json in advance" do
use_cassette "server1" do
assert HTTPotion.get("http://localhost:34000/server", []).body =~ %r/test_response/
assert HTTPotion.get("http://localhost:34000/server", []).body =~ ~r/test_response/
end
end

test "forcefully getting response from server, then loading from cache by recording twice" do
use_cassette "server2" do
assert HTTPotion.get("http://localhost:34000/server", []).body =~ %r/test_response/
assert HTTPotion.get("http://localhost:34000/server", []).body =~ ~r/test_response/
end

use_cassette "server2" do
assert HTTPotion.get("http://localhost:34000/server", []).body =~ %r/test_response/
assert HTTPotion.get("http://localhost:34000/server", []).body =~ ~r/test_response/
end
end

Expand All @@ -38,7 +38,7 @@ defmodule ExVCR.RecorderIBrowseTest do
test "replace sensitive data" do
ExVCR.Config.filter_sensitive_data("test_response", "PLACEHOLDER")
use_cassette "server_sensitive_data" do
assert HTTPotion.get("http://localhost:34000/server", []).body =~ %r/PLACEHOLDER/
assert HTTPotion.get("http://localhost:34000/server", []).body =~ ~r/PLACEHOLDER/
end
ExVCR.Config.filter_sensitive_data(nil)
end
Expand All @@ -47,7 +47,7 @@ defmodule ExVCR.RecorderIBrowseTest do
test "filter url param flag removes url params when recording cassettes" do
ExVCR.Config.filter_url_params(true)
use_cassette "example_ignore_url_params" do
assert HTTPotion.get("http://localhost:34000/server?should_not_be_contained", []).body =~ %r/test_response/
assert HTTPotion.get("http://localhost:34000/server?should_not_be_contained", []).body =~ ~r/test_response/
end
json = File.read!("#{__DIR__}/../#{@dummy_cassette_dir}/example_ignore_url_params.json")
refute String.contains?(json, "should_not_be_contained")
Expand Down
12 changes: 6 additions & 6 deletions test/task_runner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defmodule ExVCR.TaskRunnerTest do
ExVCR.Task.Runner.show_vcr_cassettes(["test/cassettes"])
end)

assert result =~ %r/[File Name]/
assert result =~ %r/test1.json/
assert result =~ %r/test2.json/
assert result =~ ~r/[File Name]/
assert result =~ ~r/test1.json/
assert result =~ ~r/test2.json/
end

test "delete cassettes task deletes json files" do
Expand All @@ -35,8 +35,8 @@ defmodule ExVCR.TaskRunnerTest do
ExVCR.Task.Runner.check_cassettes(record)
end)

assert result =~ %r/Showing hit counts of cassettes in/
assert result =~ %r/test1.json\s+1\s+2\s+\n/
assert result =~ %r/test2.json\s+1\s+0\s+\n/
assert result =~ ~r/Showing hit counts of cassettes in/
assert result =~ ~r/test1.json\s+1\s+2\s+\n/
assert result =~ ~r/test2.json\s+1\s+0\s+\n/
end
end

0 comments on commit cb3124c

Please sign in to comment.