2010-05-07 59 views
1

在测试ActionMailer发送传递邮件的方法方面有很好的文档。测试ActionMailer的接收方法(Rails)

但我无法弄清楚如何测试用于解析传入邮件的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被解析测试文件我有正确的线下面的错误。所以不是这样。谢谢!

回答

2

想通了。正在将TMail对象传递给“接收”方法。它应该只需要一个普通的旧字符串(不要自己解析为TMail对象)。

相关问题