有关于测试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正在解析我正确的测试文件。所以那不是它。谢谢!
答案 0 :(得分:2)
想出来。将TMail对象传递给“receive”方法。它应该只需要一个普通的旧字符串(将其解析为TMail对象)。