sendmail_spec.rb 858 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Channel::Driver::Sendmail do
  4. context 'with env var ZAMMAD_MAIL_TO_FILE present' do
  5. let(:address) { Faker::Internet.email }
  6. let(:body) { Faker::Lorem.sentence(word_count: 3) }
  7. let(:file) { Rails.root.join("tmp/mails/#{address}.eml") }
  8. around do |example|
  9. ENV['ZAMMAD_MAIL_TO_FILE'] = '1'
  10. FileUtils.rm_f(file)
  11. example.run
  12. FileUtils.rm_f(file)
  13. ENV.delete('ZAMMAD_MAIL_TO_FILE')
  14. end
  15. it 'creates mail file', :aggregate_failures do
  16. described_class.new.deliver({}, { to: address, from: address, body: body })
  17. expect(file).to exist
  18. content = File.read(file)
  19. expect(content).to match(%r{#{body}})
  20. expect(content).to match(%r{#{address}})
  21. end
  22. end
  23. end