1
我通过电子邮件发送包含确认链接的邀请。在我的功能测试中,我想检查邮件正文中包含正确的URL是这样的:ActionMailer测试中的命名路线
class InvitationSenderTest < ActionMailer::TestCase
test "invite" do
...
url = new_user_url(:www_host => 'localhost', :confirm_key => invitation.confirm_key)
assert_match /http:\/\/localhost#{url}/, mail.body.encoded
end
end
在开始url =
线,测试得到一个错误说undefined method 'new_user_url'
,而在ActionController的测试,在同一行工作没有问题。
我试图插入线:
include ActionDispatch::Routing
include ActionView::Helpers::UrlHelper
类的定义里面,但无济于事。我也尝试使用url_for
,但这也不起作用(“未定义的局部变量或方法'_routes'”)。我想我需要一些导入,但哪些?