'Rails: How can I test for the presence of ¡ in mailer text?
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | kkp |