【发布时间】:2021-12-21 12:38:41
【问题描述】:
我尝试更新此测试,但它无法比较相同的字符串,即使我将“got”输出复制并粘贴回测试用例。为什么这个 RSpec 测试失败了?
Failure/Error: expect(first_item_cost).to eq("12 x $499 = $5,988")
expected: "12 x $499 = $5,988"
got: "12 x $499 = $5,988"
(compared using ==)
代码:
first_item_cost = find('.cart-item-cost', match: :first).text
expect(first_item_cost).to eq("12 x $499 = $5,988")
RSpec 3.9
【问题讨论】:
-
我尝试更新到
RSpec 3.10,但没有帮助。 -
它们可能看起来相同,但实际上可能不同。检查
first_item_cost.encoding,然后比较两个字符串<str>.bytes。我猜那里可能有一些特殊字符。
标签: ruby-on-rails ruby rspec rspec-rails