Skip to content

Commit

Permalink
Prepare for release 0.14.0 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihumanable authored Oct 15, 2024
1 parent 75adf31 commit 019ded2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Change Log

## 0.14.0 (2024-10-15)

Changes where mocks are evaluated to prevent misuse and allow for common patterns that were not previously supported.

Pre-0.14.0 mocks would be intercepted by the `Patch.Mock.Server` and the mock value would be calculated by the server. This works for most cases, but has surprising behavior when the mock function cares about the process executing the function. Consider the following example.

```elixir
defmodule ExampleTest do
use ExUnit.Case
use Patch

test "example" do
patch(Example, :get_pid, fn -> self() end)

assert Example.get_pid() == self()
end
end
```

This would fail in pre-0.14.0 because the `fn -> self() end` would be executed by the `Patch.Mock.Server` and the pid returned would be the pid for the `Patch.Mock.Server` and not the caller's pid as the test author might expect.

0.14.0 changes this behavior and now will execute the `fn -> self() end` in the caller and return the expected result.

This also makes it much more difficult to address the `Patch.Mock.Server` directly, which is generally discouraged as this server is an implementation detail and should only be addressed by the Patch code itself. This should prevent a class of errors and confusing bugs caused by tests accidentally capturing the pid of, monitoring, or linking to the `Patch.Mock.Server`

### Improvements

- ⬆️ - \[Internal\] Mocks are now evaluated in the caller process instead of the `Patch.Mock.Server` process, see above for details.

### Breaking Changes

- 💔 - Mocks are now evaluated in the caller process instead of the `Patch.Mock.Server` process. Using the `Patch.Mock.Server` pid or interacting with the process is not advised but if your tests relied on being able to do this they may break due to this change.

## 0.13.1 (2024-05-02)

Minor bugfix to correct an issue with negative step ranges in `String.slice/2` raised by
Expand Down
12 changes: 6 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Patch.MixProject do
def project do
[
app: :patch,
version: "0.13.1",
version: "0.14.0",
elixir: "~> 1.7",
erlc_paths: erlc_paths(Mix.env()),
elixirc_paths: elixirc_paths(Mix.env()),
Expand All @@ -25,7 +25,7 @@ defmodule Patch.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
]
end

Expand Down Expand Up @@ -57,18 +57,18 @@ defmodule Patch.MixProject do
"pages/guide-book/02-patching.md",
"pages/guide-book/03-mock-values.md",
"pages/guide-book/04-spies-and-fakes.md",
"pages/guide-book/05-processes.md",
"pages/guide-book/05-processes.md"
]
],
groups_for_modules: [
"Developer Interface": [
Patch
],
"Listener": [
Listener: [
Patch.Listener,
Patch.Listener.Supervisor
],
"Mock": [
Mock: [
Patch.Mock,
Patch.Mock.History,
Patch.Mock.History.Tagged,
Expand Down Expand Up @@ -112,7 +112,7 @@ defmodule Patch.MixProject do
Patch.Mock.Values.Sequence,
Patch.Mock.Values.Throws
],
"Utilities": [
Utilities: [
Patch.Access,
Patch.Apply,
Patch.Assertions,
Expand Down

0 comments on commit 019ded2

Please sign in to comment.