我正在使用 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更好地解释单引号与双引号的细节。
关于ruby-on-rails - 如何使用 Rspec 正确显示双引号的 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47420477/