パスワード リセット メーラーを持っているので、テストで次のことを実行できるようにしたいと考えています。
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)
test-unit のように 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