gpt4 book ai didi

ruby-on-rails - 存在单引号时 RSpec `match` 失败

转载 作者:太空宇宙 更新时间:2023-11-03 17:31:12 25 4
gpt4 key购买 nike

当匹配器参数(由 Faker 生成)中偶尔出现单引号时,RSpec 示例失败。

规范示例本身:

it 'contains organizer name' do
expect(mail.body.encoded).to match organizer.name
end

输出示例:

1) PriorityRequestMailer#prioritize body contains organizer name
Failure/Error: expect(mail.body.encoded).to match organizer.name
expected "<html>...<a href=\"http://zieme-streich_905/events\">Gage O'Reilly</a>...</html>\r\n" to match "Gage O'Reilly"
Diff:
@@ -1,2 +1,66 @@
-Gage O'Reilly
+<html>
....

它看起来给定名称 Gage O'Reilly 出现在 body 中,但无论如何它都失败了。出现这种问题的原因是什么?

最佳答案

您通常不想匹配encoded。事实上,该方法的文档说

Calling this directly is not a good idea, but supported for compatibility

编码可以采用不同的编码,转换为可打印引用等。更好的想法是匹配decoded。更好的是,你可以做到

expect(mail.body).to match(...)

因为 body 对象已经有一个可以做正确事情的 match 方法。

关于ruby-on-rails - 存在单引号时 RSpec `match` 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com