0

I am trying to write the majority of my tests in documentation. They form a very helpful set of documentation.

Several of the tests have a moderate amount of setup and it would be cleanest if I could have several assertions in the doctest.

I tried the following but I get a warning about unused literal for the first value I am trying to assert against.

  iex> response = Raxx.response(200)
  ...> |> Raxx.set_header("content-type", "text/html")
  ...> |> Raxx.set_body("Hello, World!")
  ...> {head, body} =  Raxx.HTTP1.serialize(response)
  ...> :erlang.iolist_to_binary(head)
  "HTTP/1.1 200 OK\\r\\ncontent-length: 13\\r\\ncontent-type: text/html\\r\\n"
  ...> body
  "Hello, World!"

This is being done in the context of this PR https://github.com/CrowdHailer/raxx/pull/115

Peter Saxton
  • 4,466
  • 5
  • 33
  • 51
  • 2
    I think you need to use `iex>` for every new expression. `...` is for continuation of a multi line expression. – Dogbert Aug 07 '18 at 15:59
  • That doesn't work, it fails with the error `variable "body" does not exist` – Peter Saxton Aug 07 '18 at 21:47
  • 1
    https://lpaste.net/5094080115000737792 doesn't work? – Dogbert Aug 07 '18 at 23:01
  • Indeed. that does not appear to work. I have added a link to the in progress PR for more context on the setup – Peter Saxton Aug 08 '18 at 05:43
  • 2
    I tried what @Dogbert suggested, which is correct, and it worked fine here, no warnings. Maybe you can try his suggestion and point to us where a warning is still appearing? Another tip is for you to use `@doc ~S"""`, so you don't have to escape \r and \n. – José Valim Aug 09 '18 at 07:18
  • I have it working now @JoséValim thanks for the advice on the escape charachters – Peter Saxton Aug 18 '18 at 18:04

0 Answers0