Skip to content

Commit

Permalink
add conditional tests based on elixir version
Browse files Browse the repository at this point in the history
  • Loading branch information
icr4 authored and edgurgel committed Dec 22, 2024
1 parent bca171e commit 4b79392
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions test/mimic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Mimic.Test do

@stubbed 400
@private_stub 500
@elixir_version System.version() |> Float.parse() |> elem(0)

describe "no stub or expects private mode" do
setup :set_mimic_private
Expand Down Expand Up @@ -1038,14 +1039,26 @@ defmodule Mimic.Test do
}
end

test "copies struct fields" do
StructNoEnforceKeys
|> stub(:bar, fn -> @stubbed end)
if @elixir_version >= 1.18 do
test "copies struct fields" do
StructNoEnforceKeys
|> stub(:bar, fn -> @stubbed end)

assert StructNoEnforceKeys.__info__(:struct) == [
%{field: :foo, default: nil},
%{field: :bar, default: nil}
]
assert StructNoEnforceKeys.__info__(:struct) == [
%{field: :foo, default: nil},
%{field: :bar, default: nil}
]
end
else
test "copies struct fields" do
StructNoEnforceKeys
|> stub(:bar, fn -> @stubbed end)

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

test "protocol still works" do
Expand Down

0 comments on commit 4b79392

Please sign in to comment.