簡體   English   中英

RSpec帶有重音符的欄桿郵件測試

[英]RSpec rails mailer testing with accented character

我正在嘗試對Rails Mailer進行測試,當我嘗試匹配的字符串具有某些特殊字符或重音符時,它總是會中斷。

我的測試:

RSpec.describe UsersMailer, :type => :mailer do

  let(:mail) { UsersMailer.create(@user) }

  it 'includes first_name' do
    expect(mail.body.encoded).to match("#{HTMLEntities.new.encode('Félix', :named)}")
  end

end

我的電子郵件視圖:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
  <%= "#{HTMLEntities.new.encode(@user.first_name, :named)}" %>
</body>
</html>

它們之間的區別:

測試: F&eacute;lix

視圖: F&amp;eacute;lix

在沒有HTMLEntities的情況下,我的區別是:

測試: Félix

視圖: F=C3=A9lix

我正在使用Rails 4.2.rc1,不知道這有什么區別。

解決了! 剛剛在我的電子郵件視圖中添加了html_safe:

<%= "#{HTMLEntities.new.encode(@user.first_name, :named).html_safe}" %>

忘記了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM