Rails:如何测试&#161的存在;在邮件中?

发布于 2025-01-28 10:36:41 字数 515 浏览 2 评论 0原文

我正在尝试重写RSPEC Mailer测试,我无法弄清楚如何考虑特殊

<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

字符 使用一些有关如何测试倒置感叹点

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2025-02-04 10:36:41

好吧,如果您确实只想检查'是否在体内,则可以像这样编写(最后一行):

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

因此,只是与您提到的特殊字符匹配并返回的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:

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文