diff --git a/test/httpoison_base_test.exs b/test/httpoison_base_test.exs index 0f3b730..b4eebf4 100644 --- a/test/httpoison_base_test.exs +++ b/test/httpoison_base_test.exs @@ -106,27 +106,32 @@ defmodule HTTPoisonBaseTest do end test "request body using params example" do - expect(:hackney, :request, fn :get, "http://localhost?foo=bar&key=fizz", [], "", [] -> + expected_query = %{"foo" => "bar", "key" => "fizz"} + + expect(:hackney, :request, fn :get, "http://localhost?" <> query, [], "", [] -> + assert expected_query == URI.decode_query(query) {:ok, 200, "headers", :client} end) expect(:hackney, :body, fn _, _ -> {:ok, "response"} end) - assert ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"}) == - %HTTPoison.Response{ - status_code: 200, - headers: "headers", - body: "response", - request_url: "http://localhost?foo=bar&key=fizz", - request: %HTTPoison.Request{ - body: "", - headers: [], - method: :get, - options: [params: %{foo: "bar", key: "fizz"}], - params: %{foo: "bar", key: "fizz"}, - url: "http://localhost?foo=bar&key=fizz" - } + assert %HTTPoison.Response{ + status_code: 200, + headers: "headers", + body: "response", + request_url: "http://localhost?" <> request_url_query, + request: %HTTPoison.Request{ + body: "", + headers: [], + method: :get, + options: [params: %{foo: "bar", key: "fizz"}], + params: %{foo: "bar", key: "fizz"}, + url: "http://localhost?" <> url_query } + } = ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"}) + + assert expected_query == URI.decode_query(request_url_query) + assert expected_query == URI.decode_query(url_query) end test "get!/1 raises error tuple" do diff --git a/test/httpoison_test.exs b/test/httpoison_test.exs index 85e2c68..8422d11 100644 --- a/test/httpoison_test.exs +++ b/test/httpoison_test.exs @@ -19,8 +19,10 @@ defmodule HTTPoisonTest do assert args["baz"] == "bong" assert args |> Map.keys() |> length == 2 - assert Request.to_curl(response.request) == - {:ok, "curl -X GET http://localhost:4002/get?baz=bong&foo=bar"} + assert {:ok, "curl -X GET http://localhost:4002/get?" <> query} = + Request.to_curl(response.request) + + assert %{"baz" => "bong", "foo" => "bar"} == URI.decode_query(query) end) end @@ -53,7 +55,7 @@ defmodule HTTPoisonTest do end test "post charlist body" do - assert_response(HTTPoison.post("localhost:4002/post", 'test'), fn response -> + assert_response(HTTPoison.post("localhost:4002/post", ~c"test"), fn response -> assert Request.to_curl(response.request) == {:ok, "curl -X POST http://localhost:4002/post"} end) end @@ -233,7 +235,7 @@ defmodule HTTPoisonTest do end test "char list URL" do - assert_response(HTTPoison.head('localhost:4002/get'), fn response -> + assert_response(HTTPoison.head(~c"localhost:4002/get"), fn response -> assert Request.to_curl(response.request) == {:ok, "curl -X HEAD http://localhost:4002/get"} end)