I recently discovered a handy feature of rails system specs I wanted to share. This only works if you’re using the iTerm terminal on Mac.
Generate a new system test:
rails generate system_test example
Make sure the generated system test fails, for example by adding a the following:
assert_selector "h2", text: "I should fail!"
Run the test with the RAILS_SYSTEM_TESTING_SCREENSHOT
ENV variable set to inline
:
RAILS_SYSTEM_TESTING_SCREENSHOT=inline rails test:system
The failing test triggers a screenshot and renders it directly in the terminal, making it easy to debug the failure visually.
Read more about the available screenshot configurations in the official documentation.