Rails:如何测试邮件文本中是否存在 ¡?



我试图重写一个rspec邮件测试,我不知道如何解释特殊字符" this text:

<p>
You have been added to the <%= @user.organization.name %> organization in &#161;Generic!
</p>

下面是失败测试的一个片段:

it 'renders the body' do
puts @user.email
body = mail.body.encoded
#The following line is obviously incorrect, just an idea of what I'm trying to achieve
body.should match "You have been added to the #{@user.organization.name} in ¡Generic!"
end

我对基本rspec之上的一切都还是个新手,我真的需要一些关于如何测试反向感叹号😅的指导。

谢谢! !

我已经能够在控制台错误中显示正确的文本,但它仍然不匹配。我是这样做的:

it 'renders the body' do

body = mail.body.encoded
body.should match 'Hello test@email.com,'
body.should match "You have been added to the #{@user.organization.name} organization in u{00A1}Generic!"

,这里是新的错误:

Failures:
1) UserInviteMailer send_invite renders the body
Failure/Error: body.should match "You have been added to the #{@user.organization.name} organization in u{00A1}Generic!"
expected "rn----==_mimepart_6283bec023f29_1c0610c20237b9rnContent-Type: text/plain;rn charset=UTF-8rnC...ing! rn</p>rnrn  </body>rn</html>rnrn----==_mimepart_6283bec023f29_1c0610c20237b9--rn" to match "You have been added to the Generic organization in ¡Generic!"
Diff:
@@ -1,62 +1,123 @@
-You have been added to the Generic organization in ¡Generic!
+
+----==_mimepart_6283bec023f29_1c0610c20237b9
+Content-Type: text/plain;
+ charset=UTF-8
+Content-Transfer-Encoding: quoted-printable
+
+Hello test@email.com,=0D
+=0D
+You have been added to the Generic organization in =C2=A1Generic!=0D
+=0D

如果您确实只想检查¡是否在正文中,您可以这样写(最后一行):

expect(body.match?(/¡/)).to eq true

所以只是一个与您提到的特殊字符匹配的regexp,如果找到它,则返回true,然后将其用作测试匹配器的条件。

相关内容

  • 没有找到相关文章

最新更新