1

I'm using Rspec and the gem file_validators for testing and I need to put properly the output of the Quote Marks ("txt") like theses:

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

or

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"

But I'm having a failure error for show this:

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."

Someone can help me with this problem? The entire output needs to be like these:

You are not allowed to upload "rtf" files, allowed types: jpg, jpeg, gif, png
rld
  • 2,603
  • 2
  • 25
  • 39

2 Answers2

3

Single quote the string:

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

There are other answers that better explain the details of single quotes vs double quotes.

anothermh
  • 9,815
  • 3
  • 33
  • 52
1

I put this and work's:

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

thank's @anothermh

rld
  • 2,603
  • 2
  • 25
  • 39
  • 1
    You don't need `"#{str}"`. Use this instead: `expect(page).to have_content(str)` – anothermh Nov 21 '17 at 19:15
  • Why would you not have just accepted the answer given rather than essentially repeating it and then giving credit – engineersmnky Nov 21 '17 at 21:04
  • 1
    Not everyone knows [what to do when someone answers a question](https://stackoverflow.com/help/someone-answers) but hopefully @rld will read it for their next question. – anothermh Nov 21 '17 at 22:58
  • The thing was I was trying to do the code to pass, and when I get it I saw the answer of the anothermh. Nothing about the help of him but I like more the mine and I want to do quickly because of the hour and I just put here for for share, it's a one more answer for help others. Anyway thank's for show me this I will read. – rld Nov 22 '17 at 00:44
  • I'm sorry guys I was in the library and because of the time(the library closing) I don't vote up on the answer of the anothermh, I forget. And I was trying to pass the code and so when I get to pass I post my answer, for share. And yes, I'm never readed that before. Anyway thank you for the help. – rld Nov 22 '17 at 00:53