Test for contact form not working.

17 views
Skip to first unread message

nic...@gmail.com

unread,
Apr 17, 2015, 12:30:17 PM4/17/15
to rubyonra...@googlegroups.com
I'm working with Rails 4 and have developed a test that is failing and I don't understand why.

  test "message content" do
    message = messages(:two)                       
    mail = MessageMailer.new_message(message)
    assert_equal "Message from #{message.name}",      mail.subject
    assert_equal ["in...@example.com"],                              mail.to
    assert_equal message.email,                                         mail.from
    assert_match message.content,                                     mail.body.encoded
    assert_match CGI::escape(message.email),              mail.body.encoded  # Test if it is an escaped email address, which a.o. means that the @ is converted to browser-friendly code: %40.
  end

The last three test lines all three fail. I get the error message:
 FAIL["test_message_content", MessageMailerTest, 3.994477556]
 test_message_content#MessageMailerTest (3.99s)
        Expected: nil
          Actual: []
        test/mailers/message_mailer_test.rb:10:in `block in <class:MessageMailerTest>' (this refers to the assert_equal message.email line)

I don't understand why it is expected nul and actually empty.

My fixtures include:
two:
  name: MyString
  email: nore...@example.com
  content: MyString

The message mailer is:
  default from: "<nor...@example.com>"
  default to: "Website <in...@example.com>"
  def new_message(message)
    @message = message
    mail subject: "Message from #{message.name}", from: message.email
  end

Anyone got an idea what is going wrong?

Colin Law

unread,
Apr 17, 2015, 3:21:24 PM4/17/15
to rubyonra...@googlegroups.com
On 17 April 2015 at 17:16, <nic...@gmail.com> wrote:
> I'm working with Rails 4 and have developed a test that is failing and I
> don't understand why.
>
> test "message content" do
Try a
puts messages(:two).inspect
at this point to get more clues as to what is happening.

Colin
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/8d1f4561-cf2b-4a02-8154-15a0cd9319fe%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages