mandarvaze

mandarvaze

(UndefinedFunctionError) function HTTPoison.request/5 is undefined (module HTTPoison is not available

I am facing a unique(?) problem.

I have unit tests and integration tests

Both call the same set of functions.

All the integration tests pass (mix test --include integration test/integration/gateways/mercadopago_test.exs)

All the unit tests fail (mix test test/gateways/mercadopago_test.exs)

For every unit test , I get the same error :

** (UndefinedFunctionError) function HTTPoison.request/5 is undefined (module HTTPoison is not available)

Stack trace points to lib/gringotts/gateways/mercadopago.ex:264: Gringotts.Gateways.Mercadopago.commit/5

Searching for module not available points to solutions that do not apply.

Most suggest including httpoison in mix.exs - which was already have (https://github.com/aviabird/gringotts/blob/mercadopago-2020/mix.exs#L40)

Other suggestion is about elixirc_paths - which also taken care of (https://github.com/aviabird/gringotts/blob/mercadopago-2020/mix.exs#L19)

BTW, I’m a n00b at elixir, so I may be overlooking something obvious.

I’ve already asked for helped in local elixir discord channel. No luck.

Thanks for any suggestions/ideas.

Marked As Solved

al2o3cr

al2o3cr

All the unit tests start with a similar structure:

with_mock HTTPoison, post: fn _url, _body, _headers ->

that’s mocking the post function on HTTPoison. But the line that’s failing is using a lower-level HTTPoison function:

    res = HTTPoison.request(method, url, body, headers,
      opts ++ [params: [access_token: opts[:config][:access_token]]])

Under the hood, HTTPoison.post calls HTTPoison.request:

Also note this important detail from the Mock documentation

By default, only the functions being mocked can be accessed from within the test.

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

So, many versions of Elixir ago, you had to manage the applications list as you are doing here. That is no longer true and will cause issues. I’d remove that line entirely.

Have you tried the simple rm -rf _build and recompile approach?

Also, what version of elixir are you running? elixir --version

mandarvaze

mandarvaze

@al2o3cr What you say makes sense. I’m gonna use Bypass instead of Mock

But I’m wondering why do other two test (files) for cams and authorize.net that use similar pattern (and Mock) work ? I confirmed that these two directly use HTTPoison.post inside commit function - hence their with_mock block works.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I'm brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41454 115
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30840 112
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

We're in Beta

About us Mission Statement