Hi Rosa, thanks for the proposal!

My main concern with this approach is that the doctests are no longer "plug
and play". I can no longer copy and paste them into IEx and have them work.
Passing the context can be even more confusing, because you may end-up
referencing things like `context.test`, which are hard to replicate on IEx.

What I have done in these cases is to have an explicit module that I call
with a note in the docs:

Assuming your application has a MyExampleApp.client/0 that returns a
MyLibrary.Client,
you can do:

iex> client = MyExampleApp.client()
iex> MyLibrary.call(client, :foo)

or:

Assuming your application has a MyExampleApp.setup_some_args/0 that adds
some
fixtures to the database:

iex> client = MyExampleApp.setup_some_orgs()
iex> MyLibrary.run_query(some_qiery)

Then in my tests I define the MyExampleApp satisfying the conditions of the
tests.

On Mon, Oct 26, 2020 at 4:28 PM Rosa Richter <[email protected]> wrote:

>
> I'm trying to write some good examples for documentation, and I'd like
> them to be run as tests. However, there's some setup required that would be
> too verbose and not relevant for a doctest. What are the group's thoughts
> on allowing the ExUnit setup context to be available in doctests?
>
> I'm not trying to contain all of my tests in doctests; I understand that
> certain kinds of tests should remain in the test file. I'm only trying to
> write concise examples that need a little setup. One example: I need a user
> object as an argument to a business logic module, but creating a user
> object is not a relevant part of the example.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/ed0b6ff5-79aa-4d7e-a951-b802e36976c4n%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/ed0b6ff5-79aa-4d7e-a951-b802e36976c4n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KMymBrBzVdZApYyvBQ2hnS1dy8n61cNgwoUkNnuEJLFw%40mail.gmail.com.

Reply via email to