以下解决方案不是最优的(例如,每个邮件程序的附加请求+需要rack_test),但它有效:
# cat spec/features/mailer_preview_spec.rb
require 'rails_helper'
RSpec.describe 'MailerPreview', type: :feature do
before do
# Assuming you have the Capybara setup
Capybara.default_driver = :rack_test
end
it 'opens /rails/mailers and checks each link' do
visit '/rails/mailers'
expect(page.status_code).to eq(200)
links = page.all('a').map { |link| link[:href] }
links.each do |link|
expect {
visit link
}.not_to raise_error, "Expected #{link} not to fail"
end
end
end
提醒一下,请确保将
config.action_mailer.show_previews = true
设置在 test
环境中才能正常工作。