我有一个密码重置邮件,我希望能够在我的测试中执行以下操作:
assert_match edit_password_reset_path(user.password_reset_token), mail.body.encoded
# undefined method `edit_password_reset_path' for #<UserMailerTest:0xb6c2ea0>
但它因为 URL 帮助程序而崩溃,所以我必须这样做才能让我的测试运行:
assert_match "\/password_resets\/#{user.password_reset_token}\/edit", mail.body.encoded
效果很好,但看起来或感觉不太好。
似乎 ActionMailer::TestCase 不知道路径,因为以下失败:
assert_match "#{edit_password_reset_path(user.password_reset_token)}", mail.body.encoded
# undefined method `edit_password_reset_path' for #<UserMailerTest:0xb6c2ec8>
你如何像edit_password_reset_path(user.password_reset_token)
在测试单元中那样访问 URL 助手?
我从 RSpec 切换过来,这从来都不是问题,助手刚刚工作,我会这样做:
it "sends the user a password reset url" do
mail.body.encoded.should match(edit_password_reset_url(user.password_reset_token))
end