Revelry engineering blog header image lightbulb twil this week i learned. Chalkboard style

#RevTWIL: Factories v Fixtures in LiveView Testing

At Revelry, we believe in sharing and learning from one another (beliefs that are rooted in our Core Values). Among the many things we do to encourage internal knowledge exchange is to have a different team member present at each week’s Engineering Meeting. These presentations don’t have to be lengthy, formal, or complicated; in fact, many are brief, but also powerful in that they teach our Revelers something new, inspire conversation, and encourage collaboration.

In the spirit of sharing, we share our This Week I Learned presentations (aka RevTWILs”) here. We hope you find them helpful.

THIS WEEK: We offer an assortment of shared learnings from our engineering team.

Factories vs Fixtures in LiveView Testing: Factories are helpful for easily setting up data for your tests, but do not easily adapt with your application. As you make changes to your code, you’re more likely to break some tests. Fixtures require more configuration, but are hence more customized and better represent actual data in your app.

In Elixir guards, when functions would normally raise exceptions, they cause the guard to fail instead! This turned out to be especially useful for me when comparing ids of two structs, when one of the structs could potentially be nil: https://hexdocs.pm/elixir/main/patterns-and-guards.html#errors-in-guards

When using psql, the postgres cli tool, you can interject a backslash command at any point and it will ignore it after executing the command. Below is an example where we can view the table list in the middle of typing out a query.

*

*psql (14.10 (Ubuntu 14.10-1.pgdg22.04+1), server 14.5 (Debian 14.5-1.pgdg110+1)) *

*Type "help" for help. *

*campfire=# select ∗ from \d *

*campfire-# users; *

*campfire=# *

*

It looks like the restriction about Heroku Postgres only allowing extensions in the heroku_ext schema has been lifted! https://help.heroku.com/ZOFBHJCJ/heroku-postgres-extension-schema-restrictions

The issue we’ve been dealing with is that appending to streams in Phoenix LiveView can be …funky. 0.19.5 worked fine, but upwards of that version, there are problems with reordering items. We’ve been involved with and following the fixes and issues. It should be fixed with [this PR] (https://github.com/phoenixframework/phoenix_live_view/pull/2996). You can even check by saving the code sample as a .exs and running it standalone, which is pretty cool. Fingers crossed this fixes it. 

Want to learn more about Revelry and our collaborative approach to building custom software? Connect with our team.

We're building an AI-powered Product Operations Cloud, leveraging AI in almost every aspect of the software delivery lifecycle. Want to test drive it with us? Join the ProdOps party at ProdOps.ai.