Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Mailer Unit test case doesn't work (Testing 10.2.2) #9325

Closed
dr-impossible opened this issue Feb 19, 2013 · 8 comments · Fixed by #9920
Closed

Basic Mailer Unit test case doesn't work (Testing 10.2.2) #9325

dr-impossible opened this issue Feb 19, 2013 · 8 comments · Fixed by #9920

Comments

@dr-impossible
Copy link

If you implement an ActionMailer using the documentation (action_mailer_basics.html) and implement the basic test case in testing.html section 10.2.2, the test case will fail because the Message-ID headers of the expected and generated message do not match. The documentation doesn't currently explain how to work around this issue.

@steveklabnik
Copy link
Member

There is no section 10 in the ActionMailer docs. Section 6 has something about tests: http://guides.rubyonrails.org/action_mailer_basics.html#mailer-testing

It works for me. I have an app here: https://github.com/steveklabnik/issue_9325

Can you help me reproduce this?

@dr-impossible
Copy link
Author

I was referring to section 10 of "A Guide to Testing Rails Applications". The example uses the following testcase:

require 'test_helper'

class UserMailerTest < ActionMailer::TestCase
  tests UserMailer
  test "invite" do
    @expected.from    = 'me@example.com'
    @expected.to      = 'friend@example.com'
    @expected.subject = "You have been invited by #{@expected.from}"
    @expected.body    = read_fixture('invite')
    @expected.date    = Time.now

    assert_equal @expected.encoded, UserMailer.create_invite('me@example.com', 'friend@example.com', @expected.date).encoded
  end

end

This is a different test case from the one @steveklabnik linked to above Currently, I'm using gsub to strip out the Message-ID header from the expected value and the result.

@steveklabnik
Copy link
Member

Ahh, I got confused, I see where you referenced testing.html now.

That guide is still a WIP, so it will be a bit off, yes. That said, the edge version has basically the same thing. I'm not sure what the best way is to fix it.

@steveklabnik
Copy link
Member

It's probably better to test against the specific attributes rather than .encoded.

@dr-impossible
Copy link
Author

Agreed. It seems unnecessary to test the encoded version, especially since
you end up losing all the structure to the data being tested. Does the
result of an ActionMailer have a similar structure to the expected object
created in the example from the documentation?

On Tue, Feb 19, 2013 at 3:16 PM, Steve Klabnik notifications@github.comwrote:

It's probably better to test against the specific attributes rather than
.encoded.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9325#issuecomment-13795951.

@steveklabnik
Copy link
Member

I think so. Honestly, I don't write mailer tests for myself.

@nathansamson
Copy link

Same as #8128

@senny
Copy link
Member

senny commented Mar 18, 2013

Is there a reason not to write multiple asserts against the generated mail?

mail = UserMailer.create_invite('me@example.com', 'friend@example.com')
assert_equal ['friend@example.com'], mail.to
assert_equal ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants