1

那里有很好的文档来测试传递邮件的 ActionMailer 发送方法。

但我无法弄清楚如何测试receive用于解析传入邮件的方法。

我想做这样的事情:

require 'test_helper'
class ReceiverTest < ActionMailer::TestCase

  test "parse incoming mail" do
    email = TMail::Mail.parse(File.open("test/fixtures/emails/example1.txt",'r').read)
    assert_difference "ProcessedMail.count" do
      Receiver.receive email
    end
  end
end

但是我在调​​用 Receiver.receive 的行上收到以下错误

NoMethodError: undefined method `index' for #<TMail::Mail:0x102c4a6f0>
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/stringio.rb:128:in `gets'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:392:in `parse_header'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:139:in `initialize'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/stringio.rb:43:in `open'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/port.rb:340:in `ropen'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:138:in `initialize'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:123:in `new'
/Library/Ruby/Gems/1.8/gems/tmail-1.2.7.1/lib/tmail/mail.rb:123:in `parse'
/Library/Ruby/Gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:417:in `receive'

Tmail 正在解析我正确的测试文件。所以不是这样。谢谢!

4

1 回答 1

2

弄清楚了。将 TMail 对象传递给“receive”方法。它应该只使用一个普通的旧字符串(自己解析成 TMail 对象)。

于 2010-06-16T04:46:50.817 回答