Rails 教程 ch.10 测试 10.20 失败 [英] Rails Tutorial ch. 10 Test 10.20 failure
本文介绍了Rails 教程 ch.10 测试 10.20 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Rails 教程中测试 10.20 时遇到问题.使用命令后:
I have problem with test 10.20 in Rails Tutorial. After using command:
bundle exec rake test:mailers
bundle exec rake test:mailers
我收到错误:
Run options: --seed 6131
# Running:
F
Finished in 0.559132s, 1.7885 runs/s, 5.3655 assertions/s.
1) Failure:
UserMailerTest#test_account_activation [/home/adam/workspace/sample_app /test/mailers/user_mailer_test.rb:11]:
Expected: ["noreply@example.com"]
Actual: nil
1 runs, 3 assertions, 1 failures, 0 errors, 0 skips
我已经彻底检查了我的代码,但找不到不当之处,但显然我做错了.
I've thoroughly checked my code and can't find the impropriety but I'm obviously doing it wrong.
这是我的 user_mailer:
Here's my user_mailer:
class UserMailer < ActionMailer::Base
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
def password_reset
@greeting = "Hi"
mail to: "to@example.org"
end
end
user_mailer_test:
user_mailer_test:
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
end
我已将此行添加到 config/environments/test.rb:
I've added this line to config/environments/test.rb:
config.action_mailer.default_url_options = { host: 'example.com' }
我可以给点建议吗?
推荐答案
你需要在这一行添加 :from
You need to add :from
to this line
mail to: user.email, subject: "Account activation"
喜欢这个
mail to: user.email, from: "noreply@example.com", subject: "Account activation"
这篇关于Rails 教程 ch.10 测试 10.20 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文