求助:Rails系统测试失败时终端出现截图垃圾编码信息
Hey there! No worries at all about your first question—we’ve all fumbled through our first Stack Overflow posts, so no need to apologize 😊
Let me break down what’s happening here: those "garbage characters" you’re seeing are actually iTerm2 inline image protocol codes that Capybara (the tool Rails uses for system tests) is trying to use to display your failure screenshot directly in the terminal. If your terminal doesn’t support this protocol (like the default macOS Terminal.app, or many Linux terminals), it just spits out the raw code instead of rendering the image—hence the messy output with Base64-encoded filenames and image data.
Here are a few straightforward fixes to get rid of this:
1. Disable inline screenshots in your test configuration
The most permanent fix is to turn off the inline screenshot display in your Rails system test setup. Open test/application_system_test_case.rb and add this configuration line:
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] # Disable inline terminal screenshots to stop the garbage output Capybara::Screenshot.inline = false end
This will still save your failure screenshots to the tmp/screenshots directory (so you can still view them later), but it won’t try to render them directly in the terminal.
2. If you’re using RSpec instead of Minitest
If your project uses RSpec for testing, add the same configuration to your spec/spec_helper.rb or spec/rails_helper.rb:
# Put this somewhere in your RSpec setup block Capybara::Screenshot.inline = false
3. Quick temporary fix (per test run)
If you just want to suppress the output for a single test run without changing your config, set an environment variable when running your tests:
CAPYBARA_SCREENSHOT_INLINE=false rails test:system
That’s it! After making one of these changes, your terminal will go back to showing clean test output, and your failure screenshots will still be waiting for you in tmp/screenshots whenever you need to check them.
内容的提问来源于stack exchange,提问作者Conga

