Skip to content

Commit

Permalink
Include test with a struct without enforced keys
Browse files Browse the repository at this point in the history
  • Loading branch information
edgurgel committed Jun 22, 2024
1 parent d9df840 commit 7dc8745
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/mimic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ defmodule Mimic.Test do
describe "structs" do
setup :set_mimic_private

test "copies struct fields" do
test "copies struct fields with required fields" do
Structs
|> stub(:foo, fn -> :stubbed end)

Expand All @@ -960,6 +960,16 @@ defmodule Mimic.Test do
]
end

test "copies struct fields" do
StructNoEnforceKeys
|> stub(:bar, fn -> :stubbed end)

assert StructNoEnforceKeys.__info__(:struct) == [
%{field: :foo, required: false},
%{field: :bar, required: false}
]
end

test "protocol still works" do
Structs
|> stub(:foo, fn -> :stubbed end)
Expand Down
6 changes: 6 additions & 0 deletions test/support/test_modules.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ defmodule Structs do
def foo, do: nil
end

defmodule StructNoEnforceKeys do
@moduledoc false
defstruct [:foo, :bar]
def bar, do: nil
end

defimpl String.Chars, for: Structs do
def to_string(structs) do
"{#{structs.foo}} - {#{structs.bar}}"
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Mimic.copy(NoStubs)
Mimic.copy(Calculator)
Mimic.copy(Counter)
Mimic.copy(Structs)
Mimic.copy(StructNoEnforceKeys)
ExUnit.start()

0 comments on commit 7dc8745

Please sign in to comment.