【发布时间】:2016-08-06 21:03:22
【问题描述】:
有人可以通过 Michael Harty 的 10.20 Ruby on Rails 教程测试吗? 我有以下我无法理解的错误;除了我完全按照教程的说明进行操作。
例如。教程说要改成 noreply@example.com"] 但它指向这条线的错误...... 我是否应该更改此行并通知 Michael Harty 有关错误/做其他事情来修复错误?
我使用:ruby-2.3.0 rails - 4.2.2
错误:
错误[“test_account_activation”,UserMailerTest,2016-03-23 16:43:45 +0000] test_account_activation#UserMailerTest (1458751425.73s) ArgumentError: ArgumentError: 错误数量的参数(给定 0,预期 1) app/mailers/user_mailer.rb:3:in
account_activation' test/mailers/user_mailer_test.rb:6:inblock in ' app/mailers/user_mailer.rb:3:inaccount_activation' test/mailers/user_mailer_test.rb:6:inblock in 'FAIL["test_password_reset", UserMailerTest, 2016-03-23 16:43:45 +0000] test_password_reset#UserMailerTest (1458751425.83s) 预期:[“来自@example.com”] 实际:[“noreply@example.com”] test/mailers/user_mailer_test.rb:16:in `block in '
39/39: [================================================== ============] 100% 时间:00:00:03,时间:00:00:03
// user_mailer.rb
class UserMailer < ApplicationMailer
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.rb
require 'test_helper'
class UserMailerTest < ActionMailer::TestCase
test "account_activation" do
mail = UserMailer.account_activation
assert_equal "Account activation", mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
test "password_reset" do
mail = UserMailer.password_reset
assert_equal "Password reset", mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
end
我添加了将 Michael 更改为 Tatyana 的文件,但仍然出现 1 个错误,如下所示:我找到此文件并将其添加,将 michael 更改为 tatyana,但仍然出现如下错误:
错误[“test_account_activation”,UserMailerTest,2016-03-23 16:43:44 +0000]
test_account_activation#UserMailerTest (1458751424.20s)
ActionView::Template::Error: ActionView::Template::Error: 缺少要链接的主机!请提供 :host 参数,设置 default_url_options[:host],或设置 :only_path 为 true
app/views/user_mailer/account_activation.html.erb:9:in _app_views_user_mailer_account_activation_html_erb__2380038393264600902_67365800'
app/mailers/user_mailer.rb:5:inaccount_activation'
test/mailers/user_mailer_test.rb:9:in block in <class:UserMailerTest>'
app/views/user_mailer/account_activation.html.erb:9:in_app_views_user_mailer_account_activation_html_erb__2380038393264600902_67365800'
app/mailers/user_mailer.rb:5:in account_activation'
test/mailers/user_mailer_test.rb:9:inblock in '
【问题讨论】:
-
to 7urkm3n:我有这个文件,但我仍然有一个错误指出我有主机丢失的模板错误?我不认为我应该更改模板而是为了摆脱错误,我添加了本地主机 3000,它仍然指向主机中的语法错误....如何修复它并通过测试 10.20 谢谢。
标签: ruby-on-rails