如何使用 Rspec 双引号的 " " 正确显示

how to show properly using Rspec the Double Quote Mark's " "

我正在使用 Rspec 和 gem file_validators 进行测试,我需要正确放置引号 ("txt") 的输出,如下所示:

expect(page).to have_content expect(page).to have_content "You are not allowed to upload \"txt\" files, allowed types: jpg, jpeg, gif, png"

double_quotes = ""txt"".html_safe
expect(page).to have_content expect(page).to have_content "You are not allowed to upload #{double_quotes} files, allowed types: jpg, jpeg, gif, png"

但是我在显示这个时遇到了失败错误:

Failure/Error: expect(page).to have_content   expect(page).to have_content "You are not allowed to upload #{double_quotes} files, allowed types: jpg, jpeg, gif, png"
   expected to find text "You are not allowed to upload "txt" files, allowed types: jpg, jpeg, gif, png" in "News CityToggle navigationHomeAdminSigned in as rubie@fayvon.netSign out×Post has not been created.New Post* TitleSubtitleFileYou are not allowed to upload \"txt\" files, allowed types: jpg, jpeg, gif, png* Content It will serve for show images about the posts."

有人可以帮我解决这个问题吗? 整个输出需要像这样:

You are not allowed to upload "rtf" files, allowed types: jpg, jpeg, gif, png

单引号字符串:

expect(page).to have_content('You are not allowed to upload "txt" files, allowed types: jpg, jpeg, gif, png')

other answers 更好地解释了单引号与双引号的细节。

我把这个和工作的:

str = "You are not allowed to upload \"txt\" files, allowed types: jpg, jpeg, gif, png"
expect(page).to have_content "#{str}"

感谢@anothermh