我在测试邮件时遇到问题。似乎用描述为带电子邮件的名称的格式为电子邮件分配属性[:to,:from,:reply_to]无效。
class MessageMailer < ActionMailer::Base
def simple
mail(
from: "Aaron Test <[email protected]>",
to: "Aaron Test <[email protected]>",
reply_to: "Aaron Test <[email protected]>"
)
end
end
EXPECTED = "Aaron Test <[email protected]>"
describe MessageMailer do
before do
@email = MessageMailer.simple
end
it "expect `from` to eq #{EXPECTED}" do
expect( @email.from ).to eq(EXPECTED)
end
it "expect `to` to eq #{EXPECTED}" do
expect( @email.to ).to eq(EXPECTED)
end
it "expect `reply_to` to eq #{EXPECTED}" do
expect( @email.reply_to ).to eq(EXPECTED)
end
end
1) MessageMailer expect `reply_to` to eq Aaron Test <[email protected]>
Failure/Error: expect( @email.reply_to ).to eq(EXPECTED)
expected: "Aaron Test <[email protected]>"
got: ["[email protected]"]
(compared using ==)
任何人都知道如何以“带有姓名的电子邮件”格式分配[to:,from:,reply_to:]?
我想念什么吗?
有保存我可以测试的电子邮件标头的其他方法吗?
好吧,我通过对电子邮件的标题哈希进行测试来得到它。
这是在rspec中测试'from','reply_to'和'to'的值的方法。
describe MessageMailer do
before do
@email = MessageMailer.simple
end
it "expect `from` to be formatted correctly" do
expect( @email.header['From'].to_s ).to eq("Aaron Test <[email protected]>")
end
it "expect `reply_to` to be formatted correctly" do
expect( @email.header['Reply-To'].to_s ).to eq("Aaron Test <[email protected]>")
end
it "expect `to` to be formatted correctly" do
expect( @email.header['To'].to_s ).to eq("Aaron Test <[email protected]>")
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句