Module: Glib::MailerTester::ClassMethods

Defined in:
lib/glib/mailer_tester.rb

Instance Method Summary collapse

Instance Method Details

#generate_preview_testsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glib/mailer_tester.rb', line 10

def generate_preview_tests
  project_root = Rails.root
  paths = Dir.glob(project_root + 'test/mailers/previews/*')
  paths.each do |file|
    require file
  end

  ActionMailer::Preview.subclasses.each do |preview_class|
    preview = preview_class.new

    preview_class.instance_methods(false).each do |mailer_method|
      test "mailer for #{preview_class}##{mailer_method}" do
        preview.send(mailer_method).deliver_now

        # See TimeFreezableMailer
        preview.try(:return_time_if_frozen)

        _assert_mail_body_unchanged("#{preview_class.name.underscore}##{mailer_method}", last_mail)

        # logfile = File.join(log_dir, "#{preview_class.name.underscore}##{mailer_method}.txt")

        # # Use rstrip to avoid trailing space issues
        # expected = File.exist?(logfile) ? File.read(logfile).rstrip : ''
        # # last_delivery = ActionMailer::Base.deliveries.last
        # # result = last_delivery.html_part.body.raw_source.rstrip

        # # result = mails.last.html_part.body.raw_source.rstrip
        # result = last_mail_body

        # logger = File.open(logfile, 'w')
        # logger.puts result
        # logger.close

        # assert_equal expected, result, "Result mismatch! #{logfile.sub(/\.txt$/, '')}"
      end
    end
  end
end