Proper testing of a rails application includes system tests, which are meant to test the app as a complete entity, verify the functionality and find miscommunications between components.
Let’s use a more modern approach and extract it into its own module. It will loop over all errors and bundle them up to fail together.
Now we can just include the module and assign the
collect_errors function to every config hook we want. In our example it will be executed after every system test that has js set to true.
Here’s an example system test. We want to test the functionality of getting redirect to the login page if the user is not logged in. The test fulfils all the criteria set in our after hook. Therefore
collect_errors will be executed afterwards.
Now no failing code will be missed by our tests. Though one important thing to note is that you can’t give back error codes from the server for expected behaviour.
Hopefully you found this helpful!