kanishka
I’m debating between using exvcr stubs or just generating lots of custom cassettes to exercise edge cases of an http get request against an external endpoint. I’m curious about the forum’s thoughts on the pros and cons of each.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes.
We’re a small ...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
BartOtten
Was just reading this article, might be helpful for you: https://medium.com/flatiron-labs/rolling-your-own-mock-server-for-testing-in-elixir-2cdb5ccdd1a0
kanishka
Interesting but too heavyweight for my tastes.
dimitarvp
That article actually re-convinced me to use
mockand not to roll my own mock server.I have already used all of them:
exvcr,mock,moxandbypass. For testing code that relies on underlying HTTP client libraries I likedmockthe most withbypassa close second.moxis amazing for a lot of testing but it doesn’t help me mock the underlying HTTP client library. I’ll usemoxwhen I write higher level code that tests working with my API client itself e.g. I will make it return{:error, :too_many_retries}and see if the higher-level code reacts properly to that.exvcrI tried to use just today but it was too opaque for me and even though the docs / GitHub page are rich on details I was unable to achieve a simple scenario – namely have twouse_cassetteblocks one inside the other (as I was testing pagination and wanted two different requests mocked, and yes I used its query parameter distinction parameter). Plus it wasn’t obvious how to use recorded (custom) cassettes. I simply gave up after 10 minutes and reached formockwhich took the same amount of time and worked right away with zero surprises (NOTE: I only usedmocktwice before and the last time was more than a year ago).Not to incline future readers too much in any particular direction as libraries evolve and get better (though some don’t) but so far
mockwas the best for testing code that relies on a lower level library (by mocking the said lower-level library seamlessly) andmoxfor testing everything in your own code where you have full control.dorgan
Folks should really give patch v0.16.0 — Documentation try(also see the cheatsheet)
The ergonomics and guarantees you get with Patch are far better than Mock or Mox in many cases. There is a comparison if you want to know how each mocking library behaves under different scenarios
kanishka
I am liking exvcr a lot now. For error cases, I started with stubs, but I am going to switch to a combination of stubs and recorded cassettes with shorten timeouts in the code under test.
Once you get in direct call, delete, and record workflow, it gets pretty efficient doing happy path tests with exvcr. The only thing that can be tricky is remembering to not use random data generation when creating input data, so that your requests match fixed data in cassettes. (I wish there was a way to specify only generating new random data when exvcr is recording new cassettes.)
Workflow:
dimitarvp
Well I still have no clue how to pre-record cassettes so there’s that.
kanishka
You can use one cassette and record multiple requests in that cassette.
For custom cassettes, you just specify the location to the custom cassette. It’s usually easier to record a cassette and then modify it into a custom cassette.
dimitarvp
Maybe I can’t talk properly but again, I seriously don’t know what to do to record a cassette EXPLICITLY – not implicitly by running a test and allowing ExVCR to store it, not that – so I can reuse it later with the custom cassettes path.
Can you give me a working example?
The workflow I am interested in:
$mysterious_commandto record an HTTP responsecustom/cassettes/pathI don’t know how to do #1.
kanishka
You select an adapter from the exvcr tutorial. Then add the appropriate setup to an exunit test for your adapter. Then wrap your call in “use_casette” with your desired cassette name. Then run the test once. After the test has run, you will find the recorded cassette in your cassettes directory.
When I am at my computer tomorrow, I will try to detail out every step above with code snippets. We use hackney/httpoison at work, in case you are using a different adapter which may have issues that I am unaware of.
For the explicit case, there is an iex helper, but I haven’t used it.
dimitarvp
OK so it’s how I thought – you have to run the test once for that. And then just point ExVCR to the place where you moved the file afterwards (the so-called custom cassettes path). Alright.
Haven’t looked up the IEx helper but you might be right that it could do explicit cassette recording. Hm, I might give it a try.