dwyl / learn-elixir

:droplet: Learn the Elixir programming language to build functional, fast, scalable and maintainable web applications!
1.61k stars 107 forks source link

How to doc test in Elixir with multiple sets of speech marks in your code #43

Open Cleop opened 7 years ago

Cleop commented 7 years ago

One of my tests uses multiple sets of double quotation marks in the expected outcome. The quotation marks have got a \ before them to cancel them out. However I am still getting the following error:

Cleop commented 7 years ago

I managed to solve the problem using: ~s(enter code here)

~s is a sigil (which means a special character). This sigil can be used to replace quotation marks when you have multiple sets. See: http://elixir-lang.org/getting-started/sigils.html#strings

So code that might originally have been:

"She said "hello"" (and causing an error) becomes ~s(She said "hello") (and no errors!)

Whilst in some instances you may normally be able to substitute double quotations for single quotes or back ticks, the sigil is what is required for doc testing.