1

我正在使用 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
4

2 回答 2

3

单引号字符串:

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

还有其他答案可以更好地解释单引号与双引号的细节。

于 2017-11-21T18:53:15.933 回答
1

我把这个和工作的:

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

谢谢@anothermh

于 2017-11-21T19:05:40.350 回答