Hi all. Is there a "correct" way of writing a unit test for a mailer which sends attachments?
I tried using the @expected variable as provided in ActionMailer::TestCase, but it led to various problems. Here's what I'm attempting... def test_notification @expected.from = '' @expected.to = '' @expected.subject = '' @expected.content_type = 'multipart/mixed; boundary="something"' body_part = TMail::Mail.new body_part.content_type = 'text/plain' body_part.body = read_fixture('notification') @expected.parts << body_part # <=== ERROR HERE attach_part = TMail::Mail.new attach_part.content_type = 'application/octet-stream' attach_part.encoding = 'base64' attach_part.body = 'abc' @expected.parts << attach_part mail = Notifier.create_notification() assert_equal @expected.encoded, mail.encoded end This gives the following error: TypeError: can't convert nil into String C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/action_mailer/ vendor/tmail-1.2.3/tmail/mail.rb:551:in `quote' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:551:in `read_multipart' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:540:in `parse_body_0' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:526:in `parse_body' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/stringio.rb:43:in `open' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/port.rb:340:in `ropen' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:524:in `parse_body' C:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.1.2/lib/ action_mailer/vendor/tmail-1.2.3/tmail/mail.rb:497:in `parts' C:/Projects/portal/trunk/test/unit/notifier_test.rb:16:in `test_notification' Line 16 is commented in the above code. Looking at mail.rb:551 suggests that body is nil, and I can confirm that the body passed in was not nil. I know I can just not use @expected and check each bit of the mail separately, but I figure @expected is there for a reason (and also, checking each bit of the mail only verifies what is supposed to be there, not what isn't.) Maybe I'm just doing things completely wrong, as I'm not 100% used to Rails 2.x yet. TX --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---