Rails:如何测试&#161的存在;在邮件中?
我正在尝试重写RSPEC Mailer测试,我无法弄清楚如何考虑特殊
<p>
You have been added to the <%= @user.organization.name %> organization in ¡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
字符 使用一些有关如何测试倒置感叹点
I'm trying to rewrite an rspec mailer test and I cannot figure out how to account for the special character ¡ in this text:
<p>
You have been added to the <%= @user.organization.name %> organization in ¡Generic!
</p>
Here's a snippet of the failing test:
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
I'm still super new to everything above basic rspec, and could really use some guidance on how to test for the presence of the inverted exclamation point ????.
Thanks!!!
UPDATE
I've was able to get the correct text displayed in the console error, but it still doesn't match. Here's how I did it:
it 'renders the body' do
body = mail.body.encoded
body.should match 'Hello [email protected],'
body.should match "You have been added to the #{@user.organization.name} organization in \u{00A1}Generic!"
and here's the new error:
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 "\r\n----==_mimepart_6283bec023f29_1c0610c20237b9\r\nContent-Type: text/plain;\r\n charset=UTF-8\r\nC...ing! \r\n</p>\r\n\r\n </body>\r\n</html>\r\n\r\n----==_mimepart_6283bec023f29_1c0610c20237b9--\r\n" 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 [email protected],=0D
+=0D
+You have been added to the Generic organization in =C2=A1Generic!=0D
+=0D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果您确实只想检查
'
是否在体内,则可以像这样编写(最后一行):因此,只是与您提到的特殊字符匹配并返回的REGEXP如果找到了,则为true,然后将其用作测试匹配器的条件。
Well if you indeed only want to check if the
¡
is in the body, you could write it (the last line) up like this:So just a regexp that matches the special character you mentioned, and returns true if it is found, then use that as the condition for the test matcher.