我被要求编写一些测试来确认文本是否包含在PDF文件中。我遇到过PDF阅读器gem,它在从文件中渲染文本方面都很好,只是输出不太好。我有一段文字,例如,应该是Date of first registration of the product,但PDF阅读器认为这是Date offirstregistrationoftheproduct。因此,当我运行断言时,由于文本间距的原因,断言失败。
我的代码:
expected_text = 'Date of first registration of the product'
file = File.open(my_pdf, "rb")
PDF::Reader.open(file) do |reader|
reader.pages.each do |page|
expect(page).to have_text expected_text
end结果是出现RSpec expectation met错误。
有没有一种方法可以正确地格式化这个文本,以便我的断言可以读懂它?
https://stackoverflow.com/questions/41480782
复制相似问题