Testing ActionMailer's receive method (Rails)

Posted by Brian Armstrong on Stack Overflow See other posts from Stack Overflow or by Brian Armstrong
Published on 2010-05-07T07:43:12Z Indexed on 2010/05/07 7:48 UTC
Read the original article Hit count: 232

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!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about actionmailer