patch
patch copied to clipboard
Patching local function does not work in a string interpolation
👋
In my testing, it looks like patching does not work if a method is called from within a string interpolation expression. I took a look at the "limitations" section of the docs, and didn't see this mentioned, so I think it's a bug.
Module:
defmodule Patchtest do
def greet() do
"Hello, world!"
end
def format_greeting_1() do
greeting = greet()
"The program says: #{greeting}"
end
def format_greeting_2() do
"The program says: #{greet()}"
end
end
Test:
defmodule PatchtestTest do
use ExUnit.Case
use Patch
doctest Patchtest
test "greets the world" do
patch(Patchtest, :greet, "Hello, patched!")
assert Patchtest.format_greeting_1() == "The program says: Hello, patched!"
assert Patchtest.format_greeting_2() == "The program says: Hello, patched!"
end
end
This fails with:
1) test greets the world (PatchtestTest)
test/patchtest_test.exs:6
Assertion with == failed
code: assert Patchtest.format_greeting_2() == "The program says: Hello, patched!"
left: "The program says: Hello, world!"
right: "The program says: Hello, patched!"
stacktrace:
test/patchtest_test.exs:10: (test)