polypush135
Trying to use a config setting in place of dependency injection for testing
So I have a context that creates a post, the post also has an uploaded image that gets processed and later uploaded to S3.
Note: @processor and @uploader are being set via the config
https://github.com/PolymorphicProductions/polymorphic.productions/blob/f4daf357e876e28bf5b722cb2d2aa9ac820934d2/lib/polymorphic_productions/social/pix.ex#L12-L13
And if you look in my test config you will see
https://github.com/PolymorphicProductions/polymorphic.productions/blob/f4daf357e876e28bf5b722cb2d2aa9ac820934d2/config/test.exs#L31-L34
You can see that both modules are in my test/support/mocks
The issue I’m having is that when I go to run a test for my pix_create in my context I get a UndefinedFunctionError for the Modules I’ve defined.
❯ mix test test/polymorphic_productions/social/social_test.exs:26
Including tags: [line: "26"]
Excluding tags: [:test]
1) test pics create_pix/1 with valid data creates a pix (PolymorphicProductions.SocialTest)
test/polymorphic_productions/social/social_test.exs:26
** (UndefinedFunctionError) function PolymorphicProductions.Mocks.Processor.scale_image/1 is undefined (module PolymorphicProductions.Mocks.Processor is not available)
code: assert {:ok, %Pix{} = pix} = Social.create_pix(param)
stacktrace:
PolymorphicProductions.Mocks.Processor.scale_image("test/assets/user_avatar.jpg")
(polymorphic_productions) lib/polymorphic_productions/social/pix.ex:60: PolymorphicProductions.Social.Pix.upload_attachment/1
(polymorphic_productions) lib/polymorphic_productions/social/pix.ex:30: PolymorphicProductions.Social.Pix.changeset/2
(polymorphic_productions) lib/polymorphic_productions/social/social.ex:68: PolymorphicProductions.Social.create_pix/1
test/polymorphic_productions/social/social_test.exs:30: (test)
Finished in 0.1 seconds
16 tests, 1 failure, 15 excluded
What I’m I missing ? why does the modules fail to load? I assume I need to load the module in the config before I reference it. Just not sure if thats right or how I would go about that
Marked As Solved
polypush135
A typo was the issue
“Processer”
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









