From 4b7939231e790f900e7f912067270caf17a13d36 Mon Sep 17 00:00:00 2001 From: Alessandro Gessa Date: Fri, 20 Dec 2024 10:50:27 +0100 Subject: [PATCH] add conditional tests based on elixir version --- test/mimic_test.exs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/test/mimic_test.exs b/test/mimic_test.exs index d616d5e..c59c021 100644 --- a/test/mimic_test.exs +++ b/test/mimic_test.exs @@ -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 @@ -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