[rspec-users] Problem spec'ing ActionMailer with attachment, body not getting rendered.
rick.denatale at gmail.com
Wed Mar 18 16:33:01 EDT 2009
On Wed, Mar 18, 2009 at 4:28 PM, Rick DeNatale <rick.denatale at gmail.com>wrote:
> I've got a simple ActionMailer::Base subclass:
> class InfoMailer < ActionMailer::Base
> def info(user, zip_name)
> recipients user.email
> subject "Requested Info"
> attachment(:content_type => "application/zip",
> :filename => zip_name,
> :body => File.read(zip_name))
> body(:message => "Here is the Info that you Requested")
> I'm trying to spec this following
> describe AssetsInfoMailer do
> before(:each) do
> @user = mock_model(User,
> :email => @user_email = "somewhere at over.the.rainbow",
> :full_name => "The Wicked Witch of the West"
> ActionMailer::Base.delivery_method = :test
> ActionMailer::Base.perform_deliveries = true
> ActionMailer::Base.deliveries = 
> describe ".info" do
> before(:each) do
> @path = 'xyz.zip'
> @attachment_body = 'zip_file_contents'
> @the_mail = AssetsInfoMailer.deliver_info(@user, at path)
> @attachments = @the_mail.attachments
> it "should have the right body" do
> @the_mail.body.should == ""
> The expectation of an empty string is just to see what's actually getting
> returned, the result is:
> 'AssetsInfoMailer.info should have the right body' FAILED
> expected: "",
> got: "Attachment: xyz.zip\n" (using ==)
> It's looking like the mail template never got rendered, and body is giving
> me the attachment since it's the only part.
> I've got one other mailer method in that mailer which doesn't contain an
> attachement, and it's body comes out fine.
> I'm not sure what's going on here, and I'd appreciate any
Note that I screwed up in sanitizing the code, the mailer really is
AssetsInfoManager, and that's what's in the spec consistently.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users