2014-12-05 37 views
0

我正在嘗試對Rails Mailer進行測試,並且當我試圖匹配的字符串中有一些特殊字符或重音符號時,它總是會中斷。帶有重音字符的RSpec軌道郵件測試

我的測試:

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

當我做沒有ヶ輛,我的區別是:

測試:Félix

觀點:F=C3=A9lix

我使用Rails 4.2.rc1,不知道是否有什麼差別。

回答

0

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

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

忘記了這一點。