Trying to use a config setting in place of dependency injection for testing

testing
exunit
dependency-injection

#1

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

And if you look in my test config you will see

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


#2

A typo was the issue
“Processer”