Is it possible to color format string comparisons inside of a Mox expectation?

66 Views Asked by At

when a string equality assertion fails in an ExUnit test case, a color-formatted output is provided. Eg., for:

test "my test" do
 assert "xyz" == "xwz"
end

we get

enter image description here

But when I do it inside of expect/4:

test "my test" do
  expect(MyMock, :post, fn data ->
    assert "xyz" == "xwz"
  end)
end

no formatting is done, though:

enter image description here

Any idea if if there's a way to get the same formatting done inside of expect?

PS: What I really want is a way to get a nice string diff when I compare two long strings. Any alternatives are welcome.

PS2: Using mox 1.0.2 on OSX

1

There are 1 best solutions below

0
Everett On

If you are doing string comparisons on errors, I would suggest you avoid ANSI color codes altogether because they add a lot of "noise" to the output. ANSI color codes are optional anyhow because they are not supported on every system.

In your config/text.exs (or in which-ever environment you need to work with), add the following to disable the ANSI formatting:

config :elixir, :ansi_enabled, false

See the corresponding docs for IO.ANSI.enabled?/0