railstutorial--卡在ch10上,列出10.55

时间:2015-03-05 19:39:23

标签: ruby-on-rails ruby ruby-on-rails-4

因此,当我运行测试时出现此错误:

    FAIL["test_password_reset", UserMailerTest, 0.714736877]
 test_password_reset#UserMailerTest (0.71s)
        Expected: ["noreply@example.com"]
          Actual: ["from@example.com"]
        test/mailers/user_mailer_test.rb:23:in `block in <class:UserMailerTest>'

  39/39: [===================================================] 100% Time: 00:00:03, Time: 00:00:03

Finished in 3.45232s
39 tests, 182 assertions, 1 failures, 0 errors, 0 skips

我不确定要解决什么问题。这是我的user_mailer_test.rb:

require 'test_helper'

class UserMailerTest < ActionMailer::TestCase

  test "account_activation" do
    user = users(:michael)
    user.activation_token = User.new_token
    mail = UserMailer.account_activation(user)
    assert_equal "Account activation", mail.subject
    assert_equal [user.email], mail.to
    assert_equal ["noreply@example.com"], mail.from
    assert_match user.name,               mail.body.encoded
    assert_match user.activation_token,   mail.body.encoded
    assert_match CGI::escape(user.email), mail.body.encoded
  end

  test "password_reset" do
    user = users(:michael)
    user.reset_token = User.new_token
    mail = UserMailer.password_reset(user)
    assert_equal "Password reset", mail.subject
    assert_equal [user.email], mail.to
    assert_equal ["noreply@example.com"], mail.from
    assert_match user.reset_token,        mail.body.encoded
    assert_match CGI::escape(user.email), mail.body.encoded
  end
end

和我的user_mailer.rb:

class UserMailer < ApplicationMailer

  def account_activation(user)
    @user = user
    mail to: user.email, from: "noreply@example.com", subject: "Account activation"
  end

  def password_reset(user)
    @user = user
    mail to: user.email, subject: "Password reset"
  end
end

请帮忙。我坚持这个,我不太确定问题是什么。谢谢。

0 个答案:

没有答案