Testing ActionMailer's receive method (Rails)
- by Brian Armstrong
There is good documentation out there on testing ActionMailer send methods which deliver mail.
But I'm unable to figure out how to test a receive method that is used to parse incoming mail.
I want to do something like this:
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
But I get the following error on the line which calls 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 is parsing the test file I have correctly. So that's not it. Thanks!