Hi all!
I’m trying to test a function which returns an encoded string, but I can’t seem to figure out how to represent the test in a pretty way.
Given this test:
test "string formatting in tests" do
assert "{\"text\”:\”Something\\nAnother_Something\\nYet_Another_Something\",\"response_type\":\"in_channel\"}" ==
"""
{\"text\”:\”\
Something
Another_Something
Yet_Another_Something",\
\"response_type\":\"in_channel\"}\
"""
end
I get:
Assertion with == failed
code: assert "{\"text”:”Something\\nAnother_Something\\nYet_Another_Something\",\"response_type\":\"in_channel\"}" == "{\"text”:”Something\nAnother_Something\nYet_Another_Something\",\"response_type\":\"in_channel\"}"
left: "{\"text”:”Something\\nAnother_Something\\nYet_Another_Something\",\"response_type\":\"in_channel\"}"
right: "{\"text”:”Something\nAnother_Something\nYet_Another_Something\",\"response_type\":\"in_channel\"}"
If you notice, the error is due to the extra slash missing in the right expression. As far as I understand, the extra slash is simply to escape the actual slash in the breakline character… but seems like Elixir gets it literally.
The reason why I’m interested in this is because the "text"
property of the JSON has a huge list and I figured it would make the tests more readable to represent it with a HEREDOC… but I’m having doubts as if it’s possible. How would you approach this?