Skip to content

Unable to stub Integer.to_string/2 #28

@bterone

Description

@bterone

Issue

Trying to stub the Integer.to_string/2 method does not work.

Environment

  • Elixir 1.11.4 (compiled with Erlang/OTP 23)
  • Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Steps to reproduce

# test_helper.exs
Mimic.copy(Integer)

ExUnit.start()
# test/sometest.exs
defmodule SomeTest do
  use ExUnit.Case
  use Mimic

  test "greets the world" do
    stub(Integer, :to_string, fn _ -> "STUB" end)
    stub(Integer, :to_string, fn _, _ -> "STUB" end)

    random = Integer.to_string(5)

    assert random == "STUB"
  end
end

It seems the above test will fail, but if it's for some other method, like Integer.digits/1 it passes.

Not really sure what could be the issue without further investigation. 🤔

EDIT: I'll be more than happy to open an example repo reproducing the issue 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions