I’m working on a library, but I’m not sure how to write tests for it that involve configuration; particularly where the configuration specifies an OTP app that it should work with so I can use Application.app_dir(:my_app)
(for example).
Configuration example: config :my_library, otp_app: :my_app
Is there a “standard” way of setting up another test-only OTP app that would consume a library in tests? Perhaps I’m thinking about this incorrectly, but I’d like to do something analogous to Ruby where a gem sets up a dummy rails app during tests (if it were a Rails-oriented gem), and asserts the app behaves correctly.
The closest examples I can find is Gettext and the Phoenix Endpoint tests
-
Gettext sets up a fixture for a test application, but as far as I can see, it’s not really an app that’s mounted. It seems to be “mocking” an app setup, but with only the resources it needs. The test_helper.exs loads the mock application.
https://github.com/elixir-lang/gettext/blob/master/test/gettext_test.exs
https://github.com/elixir-lang/gettext/blob/master/test/test_helper.exs
https://github.com/elixir-lang/gettext/tree/master/test/fixtures/test_application -
Phoenix.Endpoint I think assumes the test module itself as the test application, and checks against that. https://github.com/phoenixframework/phoenix/blob/master/test/phoenix/endpoint/endpoint_test.exs
I guess I could always all functions that accept an options
keyword list that would allow me to override whatever I want just for tests; but still, I was curious if there’s a way of doing accomplishing this.