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

888 views Asked by At

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 [email protected] 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
2

There are 2 answers

0
anothermh On BEST ANSWER

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.

5
rld On

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