Ruby on rails ActionMailer测试中的命名路由

Ruby on rails ActionMailer测试中的命名路由,ruby-on-rails,ruby-on-rails-3,actionmailer,Ruby On Rails,Ruby On Rails 3,Actionmailer,我通过包含确认链接的电子邮件发送邀请。在功能测试中,我想检查邮件正文是否包含正确的URL,如下所示: class InvitationSenderTest < ActionMailer::TestCase test "invite" do ... url = new_user_url(:www_host => 'localhost', :confirm_key => invitation.confirm_key) assert_match /http

我通过包含确认链接的电子邮件发送邀请。在功能测试中,我想检查邮件正文是否包含正确的URL,如下所示:

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\u作为
,但也不起作用(“未定义的局部变量或方法“\u路由”)。我想我需要一些导入,但是哪个?

您可以包括动态生成的url帮助器模块,然后使用它定义的任何url帮助器,如下所示:

class InvitationSenderTest < ActionMailer::TestCase
  include Rails.application.routes.url_helpers

  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
类邀请SenderTestlocalhost',:confirm\u key=>invitation.confirm\u key) 断言匹配/http:\/\/localhost{url}/,mail.body.encoded 结束 结束
class InvitationSenderTest < ActionMailer::TestCase
  include Rails.application.routes.url_helpers

  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