egze
How to stub Req in development?
In the docs it says I can stub Req in tests with a config like this:
# config/test.exs
config :myapp, weather_req_options: [
plug: {Req.Test, MyApp.Weather}
]
What I want is - the same but for development to not make real API calls (they cost money) but to play with the logic.
I added the same config for development, and added this to application.ex
Req.Test.stub(MyApp.Weather, fn conn ->
Req.Test.json(conn, %{"celsius" => 25.0})
end)
but when I make a call in iex, I get an error ** (RuntimeError) cannot find mock/stub MyApp.Weather in process #PID<0.451.0>
Only when I rerun the Req.Test.stub snippet in iex, then it gets stubbed.
Can I somehow configure Req to globally stub in development?
It works if also add it to .iex.exs but it will then only stub in iex session.
Marked As Solved
egze
I think I came up with a solution. I implemented a plug module MyApp.WeatherStub with a call function and configured Req to use it in development.
Last Post!
D4no0
You can also take a look at bypass: Bypass — bypass v2.1.0
Since it’s starting an actual web server, you shouldn’t have any problems with process scopes from tests.
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









