Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

### Bug Fixes

- Fix expect_request! when multiple requests are made to the same URL with different bodys.
When a `:body` matcher is used, the matcher is now prefering that over Expectations that omitted this.

## v0.2.5 (2025-08-15)

### Bug Fixes

- Fixed `http_client` option not being allowed in `expect_request!`

## v0.2.4 (2025-08-15)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ by adding `http_ex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:http_ex, "~> 0.2.5"}
{:http_ex, "~> 0.2.6"}
]
end
```
13 changes: 7 additions & 6 deletions lib/http_ex/backend/mock/expectation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,10 @@ defmodule HTTPEx.Backend.Mock.Expectation do
...> }
...> )
...>
...> match == expectation_1
true
...> match
expectation_2
iex> vars
%{}
%{"api_version" => "v1"}
iex> {:ok, match, vars} =
...> Expectation.find_matching_expectation(
...> expectations,
Expand All @@ -785,8 +785,8 @@ defmodule HTTPEx.Backend.Mock.Expectation do
...> }
...> )
...>
...> match == expectation_1
true
...> match
expectation_1
iex> vars
%{}

Expand Down Expand Up @@ -836,7 +836,8 @@ defmodule HTTPEx.Backend.Mock.Expectation do
fn {expectation, match_result} ->
{true, fields, _misses, _vars} = match_result

match_score = length(fields)
match_score =
fields |> Enum.reject(&(expectation.matchers[&1] == :any)) |> length()

expects_calls? = expectation.type == :assertion && expectation.min_calls >= 1

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule HttpEx.MixProject do
source_url: "https://github.com/wuunder/http_ex",
start_permanent: Mix.env() == :prod,
test_coverage: [tool: ExCoveralls],
version: "0.2.5"
version: "0.2.6"
]
end

Expand Down
23 changes: 23 additions & 0 deletions test/http_ex/backend/mock_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ defmodule HTTPEx.Backend.MockTest do
end
end

test "OK, using the same endpoint for multiple request but with different body's" do
Mock.expect_request!(
endpoint: "http://www.example.com/soap",
body: "can't find this one",
response: %{status: 200, body: "OK"}
)

Mock.expect_request!(
endpoint: "http://www.example.com/soap",
body: "find_this_one",
expect_body: "find_this_one",
response: %{status: 200, body: "OK"}
)

assert Mock.request(%Request{
client: :httpoison,
url: "http://www.example.com/soap",
method: :get,
body: "find_this_one"
}) ==
{:ok, %HTTPoison.Response{status_code: 200, body: "OK", headers: []}}
end

test "max calls reached" do
Mock.expect_request!(
endpoint: "http://www.example.com",
Expand Down